Skip to content

Commit

Permalink
improve invalidStatusLine by appending a []byte directly (valyala#1086
Browse files Browse the repository at this point in the history
)

* improve invalidStatusLine

* append []byte directly

* AppendUint

* negetive

* AppendInt
  • Loading branch information
tylitianrui authored Sep 1, 2021
1 parent cad867a commit d9c7573
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ tags
*.fasthttp.br
.idea
.DS_Store
vendor/
10 changes: 9 additions & 1 deletion status.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fasthttp

import (
"fmt"
"strconv"
)

const (
Expand Down Expand Up @@ -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
}

0 comments on commit d9c7573

Please sign in to comment.