Draft HTTP 1.1 parser specification Amirouche Boubekki 01 Aug 2020 17:14 UTC
I started diving into HTTP 1.1 protocol, I learned a few (useless?) things. Also I started an implementation, the tests were taken from: https://github.com/benoitc/gunicorn/tree/master/tests/requests They seem like the same as nodejs' http-parser tests. I am not sure yet whether the parser should accept a generator of bytes or a generator of chars. It seems to me a generator of byte is more robust but... I do not know everything. Mind the fact that I drop the port abstraction, I think it will be better to have library that allows to interop both ways with generator/accumulator with R6RS/R7RS ports, instead of cluttering the current spec with PORT-OR-GENERATOR. Anyway, here is a small draft document: ## `(http)` - https://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html - https://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html ### `(Http-error? obj)` Returns `#t` if `OBJ` is an HTTP error. Otherwise, it returns `#f`. ### `(http-error-message OBJ)` Return a human readable string describing the error. ### `(http-error-extra OBJ)` Return a list of objects that can help understand the error or possibly workaround it. ### `(http-request-read generator)` `GENERATOR` must generate one byte at a time. `http-request-read` returns four values: 1. A string representing the HTTP method 2. A string representing the URI 3. A pair of numbers representing the HTTP version 4. An association list representing HTTP headers where both keys and values are strings. When this procedure returns, `GENERATOR` is positioned after all headers were read, possibly at the first byte of the message body or at the end-of-file. ### `(http-request-chunks-generator generator)` `GENERATOR` must return one byte at a time. This procedure returns a generator that follow this protocol: 1. Each chunk is generated as three values. The first value is the symbol 'chunk, the second value is a list of chunk extensions and the third and last value is a generator of the bytes the current chunk. 2. Before the end-of-file object is generated, the returned generator generate two values, where the first value is the symbol `'headers` and the second value is an association list of headers. ### `(http-request-chunks-generator* generator)` `GENERATOR` must return one byte at a time. This procedure returns a generator that generate one byte at a time of every chunk contained in the body forgoing chunk extensions and trailing headers. ### `(http-request-write accumulator method uri version headers)` TODO ### `(http-request-chunks-accumulator accumulator length)` TODO