Solve issue 535 missing responses to HEAD requests, and add a test to verify

This commit is contained in:
Jordan Crawford
2018-05-23 20:53:01 +03:00
committed by Leonid Bugaev
parent 0fea94a76c
commit 18610d3555
2 changed files with 45 additions and 1 deletions
+34
View File
@@ -76,6 +76,40 @@ func responsePacket(prev *TCPPacket, payload []byte) *TCPPacket {
)
}
func TestHEADRequestNoBody(t *testing.T) {
listener := NewListener("", "0", EnginePcap, true, 10*time.Millisecond, "")
defer listener.Close()
reqPacket := firstPacket([]byte("HEAD / HTTP/1.1\r\nContent-Length: 0\r\n\r\n"))
respPacket := responsePacket(reqPacket, []byte("HTTP/1.1 200 OK\r\nContent-Length: 100\r\n\r\n"))
listener.packetsChan <- reqPacket.dump()
listener.packetsChan <- respPacket.dump()
var req, resp *TCPMessage
select {
case req = <-listener.messagesChan:
case <-time.After( time.Millisecond):
t.Error("Should return request immediately")
return
}
if !req.IsIncoming {
t.Error("Should be request")
}
select {
case resp = <-listener.messagesChan:
case <-time.After(20 * time.Millisecond):
t.Error("Should return response immediately")
return
}
if resp.IsIncoming {
t.Error("Should be response")
}
}
func TestSingleAck100Continue(t *testing.T) {
listener := NewListener("", "0", EnginePcap, true, 10*time.Millisecond, "", "")
defer listener.Close()
+11 -1
View File
@@ -369,9 +369,19 @@ func (t *TCPMessage) updateBodyType() {
case httpMethodNotFound:
return
case httpMethodKnown:
if ! t.IsIncoming &&
t.AssocMessage != nil &&
bytes.IndexByte( t.AssocMessage.Bytes(), ' ') > -1 &&
bytes.Equal( []byte("HEAD"), proto.Method(t.AssocMessage.Bytes()) ) {
// Need to check if this is a response to a head request,
// in which case the body has to be empty regardless.
t.bodyType = httpBodyEmpty
return
}
if len(lengthB) > 0 {
t.contentLength, _ = strconv.Atoi(string(lengthB))
if t.contentLength == 0 {
t.bodyType = httpBodyEmpty
} else {