From adb1d0beb2f4419adb8e6b2bb44962374920237a Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Thu, 28 Mar 2024 15:04:39 +0100 Subject: [PATCH] Improved performance --- Server.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Server.go b/Server.go index 9ac676b..873f130 100644 --- a/Server.go +++ b/Server.go @@ -2,12 +2,14 @@ package web import ( "bufio" + "bytes" "fmt" "io" "log" "net" "os" "os/signal" + "strconv" "strings" "sync" "syscall" @@ -209,7 +211,14 @@ func (s *server) handleRequest(ctx *context, method string, url string, writer i s.errorHandler(ctx, err) } - fmt.Fprintf(writer, "HTTP/1.1 %d\r\nContent-Length: %d\r\n%s\r\n%s", ctx.status, len(ctx.response.body), ctx.response.headerText(), ctx.response.body) + tmp := bytes.Buffer{} + tmp.WriteString("HTTP/1.1 ") + tmp.WriteString(strconv.Itoa(int(ctx.status))) + tmp.WriteString("\r\nContent-Length: ") + tmp.WriteString(strconv.Itoa(len(ctx.response.body))) + tmp.WriteString("\r\n\r\n") + tmp.Write(ctx.response.body) + writer.Write(tmp.Bytes()) } // newContext allocates a new context with the default state.