Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I've done perfectly adequate HTTP parsing with this Python 4-liner:

  headerText, body = text.split('\r\n\r\n', 1)
  headerLines = headerText.split('\r\n')
  method, path, protocol = headerLines[1].split(' ')
  headers = dict(line.split(':').map(str.strip) for line in lines[1:])
For production use you'd probably want something a bit faster & more robust like Mongrel's HTTP parser (itself only 166 lines of Ragel), which powers several million websites out there:

https://github.com/mongrel/mongrel/blob/master/ext/http11/ht...



That's a perfectly adequate 4-line HTTP/1.0 parser :) But for HTTP/1.1, which must support chunked transfer coding [1], this won't work.

[1] https://tools.ietf.org/html/rfc7230#section-4.1




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: