Browse Source

improve invalidStatusLine by appending a `[]byte` directly (#1086)

* improve invalidStatusLine

* append []byte directly

* AppendUint

* negetive

* AppendInt
tyltr 4 months ago
parent
commit
d9c75732a6
2 changed files with 10 additions and 1 deletions
  1. 1 0
      .gitignore
  2. 9 1
      status.go

+ 1 - 0
.gitignore

@@ -4,3 +4,4 @@ tags
 *.fasthttp.br
 .idea
 .DS_Store
+vendor/

+ 9 - 1
status.go

@@ -2,6 +2,7 @@ package fasthttp
 
 import (
 	"fmt"
+	"strconv"
 )
 
 const (
@@ -181,5 +182,12 @@ func statusLine(statusCode int) []byte {
 
 func invalidStatusLine(statusCode int) []byte {
 	statusText := StatusMessage(statusCode)
-	return []byte(fmt.Sprintf("HTTP/1.1 %d %s\r\n", statusCode, statusText))
+	// xxx placeholder of status code
+	var line = make([]byte, 0, len("HTTP/1.1 xxx \r\n")+len(statusText))
+	line = append(line, []byte("HTTP/1.1 ")...)
+	line = strconv.AppendInt(line, int64(statusCode), 10)
+	line = append(line, []byte(" ")...)
+	line = append(line, []byte(statusText)...)
+	line = append(line, []byte("\r\n")...)
+	return line
 }