Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds typed Header API to cohttp-eio.
This is the first PR in this series. I will open additional PRs that will build on this PR and which will use the header api defined here. Future PRs will address changes required in Request, Response, (Server?) and Client modules. This is mostly to ease review and merge.
Usages of the new API can be seen in the header.md tests.
A Brief Overview
The header functionality implemented in the module
Header
aims to address the following core requirements,For (1) and (2) we define an extensible GADT -
where
'a
defines the header type. For example to defineContent-Type
header we define it asThis ensures that valid Content-Type header is an
int
.The current PR provides implementation for three common HTTP headers,
Content-Type
andTransfer-Encoding
and a type-unsafe, generic/catch all header aptly namedH name
. The plan is to increase this number in future PRs after this PR is merged.Some headers are only applicable to either requests only or response only, as such they will be defined in Request and Response module respectively. Common headers to both Request and Response will be defined in the Header module itself.
Type
'a header = ..
is also an extensible type so that end-users can define custom headers should they so desire, for example we can defineHeader1
andHeader2
as such:Tests in header.md contains a test for custom headers and its usage.
Lastly, the header values are not decoded during insertion time, they are encoded as a
'a Lazy.t
values and are only decoded on demand. This ensures that we don't incur performance penalty for those headers which we may never use. The backing store of headers is a list so insertion is 0(1)./cc @avsm @mseri