net/http: improve header parsing

This commit is contained in:
sago35
2022-07-24 11:22:49 +09:00
committed by Ron Evans
parent 171366698b
commit b64d4ec3a0
+10 -2
View File
@@ -186,12 +186,17 @@ func (c *Client) doResp(conn net.Conn, req *Request) (*Response, error) {
if err != nil {
println("Read error: " + err.Error())
} else {
idx := bytes.Index(buf[ofs:ofs+n], []byte("\r\n\r\n"))
// Take care of the case where "\r\n\r\n" is on the boundary of a buffer
start := ofs
if start > 3 {
start -= 3
}
idx := bytes.Index(buf[start:ofs+n], []byte("\r\n\r\n"))
if idx == -1 {
ofs += n
continue
}
idx += ofs + 4
idx += start + 4
scanner = bufio.NewScanner(bytes.NewReader(buf[0 : ofs+n]))
if resp.Status == "" && scanner.Scan() {
@@ -269,6 +274,9 @@ func (c *Client) doResp(conn net.Conn, req *Request) (*Response, error) {
return nil, fmt.Errorf("slice out of range : use http.SetBuf() to change the allocation to %d bytes or more", end)
}
n, err := conn.Read(buf[ofs : ofs+0x400])
if err != nil {
return nil, err
}
if n == 0 {
continue
}