Parsing a Raw HTTP Request

medium
Unit 15 · Parsing I0/2 to milestone

Implement parse_request(raw) for a raw HTTP/1.1 request (lines end with \r\n; headers end at a blank line). Return a dict with:

  • method, path (without the query string), query (a dict of lists, via urllib.parse.parse_qs), version
  • headers: a dict with lower-cased names; repeated headers are joined with ", "
  • body: exactly Content-Length bytes of the remaining text (empty if no header)

Raise ValueError for a malformed request line, a header without a colon, or a body shorter than Content-Length.

#parsing#http#networking2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Parsing a Raw HTTP Request · TechGradify