Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Heph-HTTP crate #461

Merged
merged 81 commits into from
May 24, 2021
Merged

Add Heph-HTTP crate #461

merged 81 commits into from
May 24, 2021

Conversation

Thomasdezeeuw
Copy link
Owner

@Thomasdezeeuw Thomasdezeeuw commented May 13, 2021

This is the initial version of the Heph-HTTP crate. This currently only implements a low level API with little extras, trying to go for lowest possible overhead.

Closes #54.
Closes #45.

This current commit is rather bare-bones. It does have a (barely
functional) HttpServer which can receive HTTP requests and send HTTP
responses. But plenty of things are missing (not to mention tests).
We'll mostly use a 'static lifetime, e.g. in Headers, but a short
lifetime can be used in various places when we're actually borrowing
data. For example in the Iterator implementation for Headers and
Headers::get, neither now needs to clone the HeaderName and instead lets
the name be borrowed.

This also adds another lifetime to Headers, now 'n and 'v for the name
and value.
Also fixes HeaderName::from_str to actually match (case-insensitive) the
known static headers.
This allow the implementation str to borrow the value, rather than
making an allocation.
Also some tests for the is_* functions.
This removes two dependencies: socket2 and getrandom, neither are
needed anymore. Also remove a number of unused imports.
Also expands the documentation and adds tests.
Returns the method as string.
The "Date" header, should be send with responses.
Returns major/minor version.
This adds a dependency on the httpdate crate.
Returns a static reason phrase, if known.
This commit adds four body types:
 * EmptyBody: no/empty body.
 * OneshotBody: body consisting of a single slice of bytes (&[u8]).
 * StreamingBody: body that is streaming, with a known length.
 * ChunkedBody: body that is streaming, with a unknown length. This uses
   HTTP chunked encoding to transfer the body.

The ChunkedBody body however doesn't have an implementation yet.
Since it's now used in both Bytes and BytesVectored.
Still left to do is dropping an unread chunked Body, ensuring that the
bytes are all removed from the connection.
Connection::respond now accepts a reference to the Headers, allowing the
allocating to be reused (see the my_ip example changes).

Connection::send_response now accepts the fields of the Response as
arguments because Headers is owned in it, but accepting a &Response
doesn't work because we do need ownership of the body.
Also clean up some of the lifetime naming in the body module.
For Headers::is_empty and Headers::{get,get_value} with the header not
in the list.
This doesn't test everything yet, but it's a good start. Also cleans up
the implementation in places.
Same ones from the main Heph crate.
Use a proper LICENSE file for the Heph-HTTP crate.
Implements fmt::Debug for all public types, ignores some return
arguments that aren't useful.
So it can be used in the HTTP client as well.
These will also be used in the client module.
Various edge cases and some fmt::Display implementation tests.
Still has plenty of thing to do:
 * Fix number of TODO/todo!s.
 * Add tests.
@Thomasdezeeuw Thomasdezeeuw merged commit 8075377 into master May 24, 2021
@Thomasdezeeuw Thomasdezeeuw deleted the heph-http branch May 24, 2021 15:15
@Thomasdezeeuw
Copy link
Owner Author

This still needs work, but I'm merging as is.

@Thomasdezeeuw
Copy link
Owner Author

Follow up issue #464.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add HTTP module Add HTTP module
1 participant