Commit Graph

299 Commits

Author SHA1 Message Date
Sean McArthur 833f231fa3 Upgrade to bytes 0.5 2019-11-26 12:08:28 -08:00
David Barsky a23d8edcfb Switch HttpTryFrom to TryFrom. 2019-11-26 12:08:28 -08:00
David Kellum 23fb5401fa update rand and quickcheck dev deps with usage changes 2019-11-26 12:08:28 -08:00
Sean McArthur 98e84c3515 Change request, response, and uri Builders to be by-value
Since the builders are only 1-time use anyways, it makes more sense to
enforce that through the type system, than to leave behind a panic bomb.

Most code that was just one chain should be un-affected.
2019-11-26 12:08:28 -08:00
Prasanna Loganathar 1a7d75adeb introduce TryFrom (#333) 2019-11-26 12:08:28 -08:00
David Barsky 8158916d23 Upgrade to 2018 Edition (#331)
* 2018 edition, babey!

* run `cargo fix --edition-idioms`

* yes, we do intend to drop the iterator, thanks rustc!

* cargo fmt

* aggressive min rustc version bump to fix travis

* 1.37 is not out, oops
2019-11-26 12:08:28 -08:00
Sean McArthur 697b83b65f allow deprecated uninitialized while min Rust is 1.30 2019-11-26 12:08:28 -08:00
Sean McArthur b36ea08c50 Change HeaderMap::entry to no longer return a Result
- Only types that implement `IntoHeaderName` can now be passed to
  `entry`, though they still are lazily cloned.
- Adds `HeaderMap::try_entry` that works as before, returning a `Result`
  if the key isn't a valid `HeaderName`.

This is a breaking change.
Closes #267
2019-11-26 12:08:28 -08:00
Sean McArthur 6059be7a99 Remove/rename deprecated APIs 2019-11-26 12:08:28 -08:00
Sean McArthur 55a0a0badb Use 'dyn' keyword with trait objects 2019-11-26 12:08:28 -08:00
Sean McArthur 20d04ade1c implement FusedIterator for all HeaderMap iterators (#318)
Increases minium Rust version to 1.26, when FusedIterator was
stabilized.
2019-11-26 12:08:28 -08:00
Kevin Choubacha 0cd6f5b118 Implement variant on version to require catch-all (#159) 2019-11-26 12:08:28 -08:00
Lucas Pardue d9a06a6e94 Add awareness of HTTP/3 (#294) 2019-11-26 12:08:28 -08:00
Sean McArthur fe5fefda4e start 0.2.x branch 2019-11-26 12:08:28 -08:00
Sean McArthur 64c5dd2644 v0.1.20 2019-11-26 10:26:34 -08:00
XAMPPRocky 1ee633e7a8 Refactor Method::is_idempotent for readability (#348) 2019-11-26 10:09:06 -08:00
Erick Tryzelaar fd7499ab0b Fix docs indentation (#347) 2019-11-26 10:08:19 -08:00
James 64064ac3eb Fix parsing of long host with no scheme (#351)
This change fixes an issue where an URI with no scheme, a host
part with a length greater than the max for a scheme, while only
consisting of valid characters for a scheme would fail to parse.

Rather than assuming the string being parsed is meant to contain
a scheme and returning an error if the max length for a scheme is
met, we instead extract the scheme part if it exists and validate
its length.

The trade-off is worse performance in the error case of a scheme
that is too long.
2019-11-26 10:07:37 -08:00
Sean McArthur 7742356863 Make ValueDrain eagerly collect its extra values 2019-11-26 10:03:09 -08:00
Sean McArthur e5ce34fe31 fix capacity overflows in HeaderMap::reserve 2019-11-25 16:29:21 -08:00
Sean McArthur c916e38eca Remove unused 'inner label 2019-11-25 11:36:28 -08:00
Sean McArthur 96abaae1fa Fix HeaderMap::drain double-free if drain iterator is forgotten 2019-11-25 11:35:03 -08:00
Sean McArthur 44f28adb5f v0.1.19 2019-10-15 11:46:00 -07:00
Sean McArthur 2c59983684 Improve Debug format of error types 2019-10-07 13:38:37 -07:00
Daniel Johnson ea4cc61a71 Allow % in IPv6 addresses to support zone identifiers. (#343)
https://tools.ietf.org/html/rfc6874 explains that %25 can be used to
indicate a "zone identifier", useful for IPv6 link-local addresses.
2019-10-07 13:04:51 -07:00
Sean McArthur b5ee552cff v0.1.18 2019-07-26 10:38:28 -07:00
Matthew Sherborne b633a7f2f6 Conditional compilation 2019-07-26 10:33:41 -07:00
Matthew Sherborne 21bff29f5b Added benchmarks for parsing header field names 2019-07-26 10:33:41 -07:00
Sean McArthur e755cc0fe8 Adjust HttpTryFrom for HeaderMap to be generic over the value type 2019-07-26 10:22:39 -07:00
Ophir LOJKINE 7ecbeb03f2 Implement HttpTryFrom<HashMap<String,String>> for HeaderMap (#326) 2019-07-25 10:22:13 -07:00
Guillaume Gomez 291a28912c Automatically test code examples in the README file (#314) 2019-07-15 14:50:56 -07:00
Sean McArthur 7f004434f3 Fix all deprecation warnings 2019-07-08 11:43:08 -07:00
Josh Leeb-du Toit 1cc157eaeb Export http::header::HeaderValue as http::HeaderValue (#222) 2019-06-26 13:11:05 -07:00
Sean McArthur 518b57ada5 v0.1.17 2019-04-05 09:58:09 -07:00
Kyle Huey ed3d506fbd Add headers/headers_mut accessors. (#293) 2019-04-05 09:44:36 -07:00
Sean McArthur fb68c44d09 Revert "Implementation of test and parsing for protocol relative uris (#300) (#301)" (#310)
This reverts commit 69f71dcf9f.
2019-04-02 17:48:04 -07:00
David Kellum 6c4803d282 Add http::Error::inner_ref and cause (#303)
* add Error::inner_ref() for access to inner error type

Also use `Error::inner_ref` to implement `std::error::Error::cause`
for now. When MSRV is raised to 1.30.0+, this could also be used for
`Error::source` without a breaking change.

* add Error::is helper

* rename Error::inner_ref to get_ref

* make Error::cause be the inner error's cause

None of the inner errors currently have a cause, but this is
considered (see PR discussion) the most correct implementation of
`std::error::Error::cause` and is thus future proofed.
2019-04-02 16:35:05 -07:00
Sean McArthur 256b782166 Improve Index for HeaderMap panic message to include key as string (#309) 2019-04-02 14:38:14 -07:00
Insomniak47 69f71dcf9f Implementation of test and parsing for protocol relative uris (#300) (#301)
Fixes #300
2019-03-20 14:37:46 -07:00
David Tolnay 0f9a4d230f Make eq macro compatible with rustfmt (#304)
Rustfmt currently hangs when formatting the expanded code of some of the
invocations of eq in this crate. This is a rustfmt bug which I will be
reporting, but in the meantime if you are open to it, it is possible to write
this macro in a way that generates code that can be formatted more easily and
more readably.

Affects `cargo-expand` being able to show expanded code for http.

Before:

    (b[0] == b'c' &&
    (b[1] == b'o' &&
    (b[(1 + 1)] == b'n' &&
    (b[((1 + 1) + 1)] == b't' &&
    (b[(((1 + 1) + 1) + 1)] == b'e' &&
    (b[((((1 + 1) + 1) + 1) + 1)] == b'n' &&
    (b[(((((1 + 1) + 1) + 1) + 1) + 1)] == b't' &&
    (b[((((((1 + 1) + 1) + 1) + 1) + 1) + 1)] == b'-' &&
    (b[(((((((1 + 1) + 1) + 1) + 1) + 1) + 1) + 1)] == b's' &&
    (b[((((((((1 + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1)] == b'e' &&
    (b[(((((((((1 + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1)] == b'c' &&
    (b[((((((((((1 + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1)] == b'u' &&
    (b[(((((((((((1 + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1)] == b'r' &&
    (b[((((((((((((1 + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1)] == b'i' &&
    (b[(((((((((((((1 + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1)] == b't' &&
    (b[((((((((((((((1 + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1)] == b'y' &&
    (b[(((((((((((((((1 + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1)] == b'-' &&
    (b[((((((((((((((((1 + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1)] == b'p' &&
    (b[(((((((((((((((((1 + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1)] == b'o' &&
    (b[((((((((((((((((((1 + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1)] == b'l' &&
    (b[(((((((((((((((((((1 + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1)] == b'i' &&
    (b[((((((((((((((((((((1 + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1)] == b'c' &&
    (b[(((((((((((((((((((((1 + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1)] == b'y' &&
    (b[((((((((((((((((((((((1 + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1)] == b'-' &&
    (b[(((((((((((((((((((((((1 + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1)] == b'r' &&
    (b[((((((((((((((((((((((((1 + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1)] == b'e' &&
    (b[(((((((((((((((((((((((((1 + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1)] == b'p' &&
    (b[((((((((((((((((((((((((((1 + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1)] == b'o' &&
    (b[(((((((((((((((((((((((((((1 + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1)] == b'r' &&
    (b[((((((((((((((((((((((((((((1 + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1)] == b't' &&
    (b[(((((((((((((((((((((((((((((1 + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1)] == b'-' &&
    (b[((((((((((((((((((((((((((((((1 + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1)] == b'o' &&
    (b[(((((((((((((((((((((((((((((((1 + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1)] == b'n' &&
    (b[((((((((((((((((((((((((((((((((1 + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1)] == b'l' &&
    (b[(((((((((((((((((((((((((((((((((1 + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1) + 1)] == b'y'
    )))))))))))))))))))))))))))))))))))

After:

    b[0] == b'c' &&
    b[0 + 1] == b'o' &&
    b[0 + 1 + 1] == b'n' &&
    b[0 + 1 + 1 + 1] == b't' &&
    b[0 + 1 + 1 + 1 + 1] == b'e' &&
    b[0 + 1 + 1 + 1 + 1 + 1] == b'n' &&
    b[0 + 1 + 1 + 1 + 1 + 1 + 1] == b't' &&
    b[0 + 1 + 1 + 1 + 1 + 1 + 1 + 1] == b'-' &&
    b[0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1] == b's' &&
    b[0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1] == b'e' &&
    b[0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1] == b'c' &&
    b[0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1] == b'u' &&
    b[0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1] == b'r' &&
    b[0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1] == b'i' &&
    b[0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1] == b't' &&
    b[0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1] == b'y' &&
    b[0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1] == b'-' &&
    b[0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1] == b'p' &&
    b[0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1] == b'o' &&
    b[0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1] == b'l' &&
    b[0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1] == b'i' &&
    b[0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1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 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1] == b'-' &&
    b[0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1] == b'o' &&
    b[0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1] == b'n' &&
    b[0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1] == b'l' &&
    b[0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1] == b'y'
2019-03-15 16:03:58 -07:00
lzutao 573719a95e Create link references to HeaderName in HeaderMap (#305) 2019-03-15 11:42:28 -07:00
Sean McArthur cdce986139 v0.1.16 2019-02-19 12:36:02 -08:00
Sean McArthur 73ff2c744e Improve path parsing performance by using slice iterator instead of indexing Bytes (#297) 2019-02-18 14:57:38 -08:00
Sean McArthur c8abe409ce Permit more characters in URI paths (#296) 2019-02-18 13:24:25 -08:00
Sean McArthur c22f507158 v0.1.15 2019-01-22 11:26:54 -08:00
Sean McArthur 9503adeb56 Fix Uri::host to include brackets of IPv6 literals (#292) 2019-01-22 11:22:15 -08:00
Sean McArthur bee2e5eb2e Add convenience Uri getters (#287)
Parts of the `Uri` that now have specific types meant that several
methods were deprecated, such as `Uri::scheme()` for
`Uri::scheme_part()`. This means that many use-cases have extra
`map`ping code to get the original value.

This adds convenience getters to reduce the need to map when the actual
type is not needed:

- `scheme_str`
- `port_u16`
2019-01-07 16:18:53 -08:00
kazuhiko kikuchi e4998b601c Add method_ref, uri_ref, headers_ref to request::Builder (#284) 2018-12-19 10:21:25 -08:00
Carl Lerche dc2f85499b Bump version to v0.1.14 (#279) 2018-11-21 13:37:08 -08:00
Per Grön 45a9612a75 Expose http::headers::{IterMut, ValuesMut}
It seems like these exports were not omitted intentionally.

The inability to name these types is giving me some grief in my work in tower-grpc where I'm trying to wrap HeaderMap in a wrapper that exposes an API in terms of gRPC metadata.
2018-11-08 09:18:56 -08:00