kbandla / dpkt

fast, simple packet creation / parsing, with definitions for the basic TCP/IP protocols
Other
1.08k stars 270 forks source link

HTTP HEAD Responses cannot be processed correctly #648

Open JannisBush opened 1 year ago

JannisBush commented 1 year ago

Describe the bug HTTP HEAD Responses are currently not parsed correctly. As there is no body, the library raises an Error and it does not seem possible to ignore it for HEAD responses.

To Reproduce Steps to reproduce the behavior:

import dpkt

head_response = b"HTTP/1.1 200 OK\r\nContent-Length: 10\r\n\r\n"
resp = dpkt.http.Response(head_response)

-> dpkt.dpkt.NeedData: short body (missing 10 bytes)

Expected behavior Option to tell the Response that it is a head_response such that it does not raise an Exception (dpkt.http.Response(head_response, head_response=True)).

Additional context This problem was already raised in the past: https://github.com/kbandla/dpkt/issues/77 But if I understand the code correctly, only status codes 1XX, 204, and 304 are handled correctly at the moment.