HTTP request parsing
Parse a raw HTTP request. The request is a string with lines separated by CRLF (\r\n); the request line comes first (METHOD PATH VERSION), followed by zero or more 'Name: Value' header lines, terminated by a blank line. Return [method, path, version, headers] where headers is a dict mapping lowercased header names to their trimmed values. Assume each header name appears at most once.
Implement
parse_request(raw: str) → listExamples
in
["GET /index.html HTTP/1.1\r\nHost: example.com\r\nAccept: text/html\r\n\r\n"]out["GET","/index.html","HTTP/1.1",{"host":"example.com","accept":"text/html"}]What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 20 min
solution.py
InputExpectedGot
["GET /index.html HTTP/1.1\r\nHost: example.com\r\nAccept: text/html\r\n\r\n"]["GET","/index.html","HTTP/1.1",{"host":"example.com","accept":"text/html"}]not run yetsample