mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-15 12:23:41 +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 {
|
if err != nil {
|
||||||
println("Read error: " + err.Error())
|
println("Read error: " + err.Error())
|
||||||
} else {
|
} 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 {
|
if idx == -1 {
|
||||||
ofs += n
|
ofs += n
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
idx += ofs + 4
|
idx += start + 4
|
||||||
|
|
||||||
scanner = bufio.NewScanner(bytes.NewReader(buf[0 : ofs+n]))
|
scanner = bufio.NewScanner(bytes.NewReader(buf[0 : ofs+n]))
|
||||||
if resp.Status == "" && scanner.Scan() {
|
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)
|
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])
|
n, err := conn.Read(buf[ofs : ofs+0x400])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user