mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-03 06:27:47 +00:00
net/http: improve header parsing
This commit is contained in:
+10
-2
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user