tiny_httpd icon indicating copy to clipboard operation
tiny_httpd copied to clipboard

Better data structure for headers

Open craff opened this issue 2 years ago • 2 comments

Headers may have much more that 10 fields and usually use common headers (see []https://en.wikipedia.org/wiki/List_of_HTTP_header_field])

We could encode header_field as type _ header_field = | Connection : 'a header_field | Content_type : 'a header_field | Cookie : Request.t header_field | Set-cookie : Response.t header_field | ... | Other : string -> 'a header_field

and the headers itself as a hashtable or other data structure a bit more efficient that association list ? Not clear to me what is the best data structure for medium size maps.

craff avatar Dec 16 '21 05:12 craff

I think it's probably overkill. I like the simplicity of current's structure :), and that it's easy to give a list of pairs.

I might be amenable to string Map.Make(String).t as the structure.

c-cube avatar Dec 16 '21 15:12 c-cube

I think another idea would be;

For request header some callbacks called for specific keys, avoiding searching the headers. Call backs could be organised in a tree. This would handle for instance cookies, keep_alive, etc ...

For response a bunch of function to set the most used headers.

craff avatar Dec 18 '21 03:12 craff

I think you can close this issue... I still believe we could improve parsing/handling of headers and cookies, but I don't think I will be working on that soon.

craff avatar Jan 18 '23 07:01 craff

I don't think we need something more complicated.

c-cube avatar Jan 20 '23 15:01 c-cube