Skip to content

Commit b64d4ec

Browse files
sago35deadprogram
authored andcommitted
net/http: improve header parsing
1 parent 1713666 commit b64d4ec

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

net/http/tinygo.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,17 @@ func (c *Client) doResp(conn net.Conn, req *Request) (*Response, error) {
186186
if err != nil {
187187
println("Read error: " + err.Error())
188188
} else {
189-
idx := bytes.Index(buf[ofs:ofs+n], []byte("\r\n\r\n"))
189+
// Take care of the case where "\r\n\r\n" is on the boundary of a buffer
190+
start := ofs
191+
if start > 3 {
192+
start -= 3
193+
}
194+
idx := bytes.Index(buf[start:ofs+n], []byte("\r\n\r\n"))
190195
if idx == -1 {
191196
ofs += n
192197
continue
193198
}
194-
idx += ofs + 4
199+
idx += start + 4
195200

196201
scanner = bufio.NewScanner(bytes.NewReader(buf[0 : ofs+n]))
197202
if resp.Status == "" && scanner.Scan() {
@@ -269,6 +274,9 @@ func (c *Client) doResp(conn net.Conn, req *Request) (*Response, error) {
269274
return nil, fmt.Errorf("slice out of range : use http.SetBuf() to change the allocation to %d bytes or more", end)
270275
}
271276
n, err := conn.Read(buf[ofs : ofs+0x400])
277+
if err != nil {
278+
return nil, err
279+
}
272280
if n == 0 {
273281
continue
274282
}

0 commit comments

Comments
 (0)