Repository navigation
Replies: 1 comment
|
For a simple angstrom header parser, a bit more strict than ours, we can also have a look at https://github.com/tmattio/dream-encoding |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
This is not yet an RFC but collects -- in fact, mostly copy-pastes -- some thoughts from @samoht and @dinosaure in the discussion on #747
Since we are breaking the
Headermodule anyway, it seems reasonable to explore if the headers could be turned into an heterogeneous list with typed keys to know if an entry is a list of string of just a string or with even finer types. The goal would be to only have one get function. Something along the lines of:This could also allow us to address #726 at the same time.
There are a few things to keep in mind.
One is that that the header fields are practically infinitely extensible:
So we should make sure to have a way to have custom string getters that are built from a
stringand return astring listfor the use-cases that require custom headers.In principle, we could try to auto-generate most of the getters from the list at IANA and if we have a nice library for parsing the various types we could make the headers as type-safe as they can be.
For a concrete example of such a thing,
mrmimeimplements this with theFieldmodule. From direct experience and its usage in several projects (such asocaml-dkimorptt), this approach comes with many benefits (the main is to extract values directly to their OCaml form). However, a question remains: which kind of type we want to handle. RFC 5322 defines an exhaustive list of what an email parser should be aware (From,Date, etc.) andmrmimeimplements only them. I think HTTP should list them too.If you want to go this way, it requires more (orthogonal) works:
Content_type.t/Accept_*.t/etc.Headerto be a heterogeneous list of GADT constructorsUnstructuredformrmime)It requires more work about the parser of fields and maybe it's a good time to:
unstrctrd(to be sure to handle any cases)Unstrctrd.of_stringAnd post-process values with associated parser (the
Content-Typeparser, theAccept-*parser, etc.).All reactions