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 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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
Header
module 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
string
and return astring list
for 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,
mrmime
implements this with theField
module. From direct experience and its usage in several projects (such asocaml-dkim
orptt
), 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.) andmrmime
implements 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.Header
to be a heterogeneous list of GADT constructorsUnstructured
formrmime
)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_string
And post-process values with associated parser (the
Content-Type
parser, theAccept-*
parser, etc.).Beta Was this translation helpful? Give feedback.
All reactions