Using `time::Tm` directly in HTTP header fields requires special handling to parse and format
the header values., this stops us from using the header macros. By wrapping `time::Time` in a
`HttpDate`, we can use the `FromStr` and `Display` traits of `HttpDate` like for most other values.
BREAKING_CHANGE: All code using one of the `Date`, `Expires`, `If-Modified-Since`,
`If-Unmodified-Since`, `Last-Modified` header fields needs to wrap `time::Tm`
with `HttpDate`. Removed `FromStr` trait of `Date`, `If-Modified-Sice` and `If-Unmodified-Sice`,
implementing the trait here is inconsistent with other headers.
The results of benches/client.rs are below.
Before:
running 1 test
test bench_mock_hyper ... bench: 321609 ns/iter (+/- 18127)
After:
running 1 test
test bench_mock_hyper ... bench: 239319 ns/iter (+/- 29938)
Adds strong and weak comparison to EntityTag as described in the RFC,
add tests for this. Make EntityTag safe to use by hiding the tag field,
this prevents users from inserting malicious values for the tag. Invalid
values can screw up header formatting and may allow to insert headers.
Introduce EntityTag::new(), .tag() and .set_tag() methods. Fix Display
trait for EntityTag. DQUOTES were missing. Remove custom formatting in ETag
header. Improve docs.
BREAKING_CHANGE: EntityTag.tag is private, use EntityTag.tag() and
EntityTag.set_tag("foobar") to access it.
This includes a custom BufReader, since the one in libstd doesn't allow
reading additional data into the buffer without consuming it. This is
required because some connections may send shorter packets, and so we
need to perform multiple reads. After each read, the contents of the
buffer are passed to httparse to see if have a valid message. If so, the
proper amount of bytes are consumed. The additional bytes are left in
the buffer since they are the beginning of the body.
The buffer in this BufReader also grows in size, compared to the libstd
which is sized once. This is because we start with a smaller buffer,
since the majority of messages will be able to include their head in a
packet or 2. Therefore, it's a wasteful performance hit to allocate the
maximum size for every message. However, some headers can be quite big,
and to allow for many of them to be set, we include a maximum size. Once
we've hit the maximum buffer size, and still haven't determined the end
of the headers, a HttpTooLargeError will be returned.
Closes#389
This commit fixes `cargo build` and `cargo test`.
Method lookup on traits seems to have changed to force
`impl TraitName` expressions to be more specific. That means that
`method` will not be found anymore on an object of type `&Trait+Send`,
unless you provide an `impl Trait+Send`.
Now `NetworkStream` and `HeaderFormat` trait implementations
are done against `* + Send`, which helps the compiler to find the
respective `downcast*` method implementations once again.
httparse is a http1 stateless push parser. This not only speeds up
parsing right now with sync io, but will also be useful for when we get
async io, since it's push based instead of pull.
BREAKING CHANGE: Several public functions and types in the `http` module
have been removed. They have been replaced with 2 methods that handle
all of the http1 parsing.
BREAKING CHANGE: added requirement that all HeaderFormat implementations
must also be fmt::Debug. This likely as easy as slapping
#[derive(Debug)] on to any custom headers.
All instances of `old_io` and `old_path` were switched to use the new
shiny `std::io`, `std::net`, and `std::path` modules. This means that
`Request` and `Response` implement `Read` and `Write` now.
Because of the changes to `TcpListener`, this also takes the opportunity
to correct the method usage of `Server`. As with other
languages/frameworks, the server is first created with a handler, and
then a host/port is passed to a `listen` method. This reverses what
`Server` used to do.
Closes#347
BREAKING CHANGE: Check the docs. Everything was touched.
Using floating point numbers is problematic because comparison is inexact.
They also take more space than integral numbers in this case.
Add `FromPrimitve`, `ToPrimitive` and `Default` traits to quality newtype.
Closes: #330
BREAKING_CHANGE: Replace f32 quality values in quality items with a
Quality(u16) newtype. Valid values are from 0 to 1000.
Change AcceptorPool to not spawn detached threads anymore. This,
together with the recent `Send` changes, allows the `work` closure to
close over non-`'static` data.
This doesn't change the high-level `Server` interface, because that
would make it's `listen` a blocking call (it's currently non-blocking)
- which would be a breaking change.