Improved performance

This commit is contained in:
Eduard Urbach 2024-03-28 15:04:39 +01:00
parent 5af7efcdbd
commit adb1d0beb2
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0

View File

@ -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.