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.