Sean McArthur
bcccb669a4
Make all usage of Bytes private
...
Removes `from_shared` and `try_from` constructors for all types.
2019-12-02 13:12:38 -08:00
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 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
Lucas Pardue
d9a06a6e94
Add awareness of HTTP/3 ( #294 )
2019-11-26 12:08:28 -08:00
Sean McArthur
2c59983684
Improve Debug format of error types
2019-10-07 13:38:37 -07:00
Matthew Sherborne
b633a7f2f6
Conditional compilation
2019-07-26 10:33:41 -07:00
Ophir LOJKINE
7ecbeb03f2
Implement HttpTryFrom<HashMap<String,String>> for HeaderMap ( #326 )
2019-07-25 10:22:13 -07:00
Sean McArthur
7f004434f3
Fix all deprecation warnings
2019-07-08 11:43:08 -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 + 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+ 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
Bastien Orivel
e291a32087
Support more tokens for header names
...
According to the RFC both `^` and ` are valid in a header name.
This is also making some wpt test fail in servo since they're trying to
build a headername with all those characters
2018-11-01 13:03:55 -07:00
Sean McArthur
796335d1f5
implement fmt::Display for HeaderName ( #249 )
2018-09-11 20:05:40 -07:00
Carl Lerche
bccac1427a
Add HttpTryFrom impls for &Self ( #234 )
2018-08-06 21:43:31 -07:00
Simon Smith
eeb82cdbc8
header name: add from_static method ( #195 )
...
* header name: add from_static method
* header name: move tests into tests module
2018-05-01 11:27:34 -07:00
Sean McArthur
f7218171fa
fix conflicts with new TryFrom trait, deprecated AsciiExt ( #194 )
2018-04-06 11:21:17 -07:00
Nikolay Kim
6701b124b4
websocket handshake related headers ( #162 )
2018-01-17 16:29:26 -08:00
Carl Lerche
2dd15d9d3f
Add HeaderName::from_lowercase ( #120 )
...
HTTP/2.0 requires that all header names be provided with only lowercase
characters. Using uppercase characters must result in a PROTOCOL_ERROR.
In order to avoid scanning the string multiple times while parsing,
provide a lowercase parse variant.
2017-08-29 21:37:23 -04:00
Sean McArthur
acc09a90ca
remove panics from using a string as key to the HeaderMap
...
- Splits `HeaderMapKey` into `IntoHeaderName` and `AsHeaderName`.
- `IntoHeaderName` is a bounds on `insert` and `append`. It is
implemented for `HeaderName` and `&HeaderName`, since those are
infallible conversions, so `insert`/`append` won't panic, nor do they
need to change to return a `Result`.
- `IntoHeaderName` is also implemented for `&'static str`, since an
invalid header name in a static string is definitely a programmer error.
- `AsHeaderName` is the bounds on `get`, `get_mut`, `contains_key`, etc.
Any method that is just used for searching. The trait is implemented
for `HeaderName` and for `str` variants, but they no longer panic on
invalid string names. It simply returns `None` as the illegal header
clearly is not in the map.
- All methods that took `&K where K: AsHeaderName` now take `K by value.
This follows the pattern of std and elsewhere when accepting an
argument that is `AsRef<Something>`. This allows code like `map[HOST]`
and `map.get("host")` to both work.
- `entry` has been changed because of this. The reason to use `entry` is
to prevent unnecessary work if the key already exists in the map. So,
it has a `AsHeaderName` bounds, to allow the searching to use a `&str`
without having to allocate a `HeaderName`. If not found, and the string is
valid, then it can allocate and insert. Because the parsing can fail,
`entry` now returns a `Result<Entry<T>, InvalidHeaderName>`.
2017-08-09 10:32:11 -07:00
Sean McArthur
ace9a94aaf
impl PartialEq for more combos of HeaderName and str
2017-08-09 10:31:11 -07:00
Carl Lerche
696ee204ff
Bring back Refresh standard header ( #93 )
2017-08-03 07:33:06 -07:00
Pyfisch
39a9a2d1ae
/s/indtended/intended
2017-08-01 12:49:01 +02:00
Sean McArthur
e6030f82f0
remove uncommon and deprecated headers
2017-07-28 17:34:55 -07:00
Alex Crichton
5e3832272b
Add owned variants for each error
...
For all fallible functions that consume `Bytes` a new `InvalidFooShared` error
has been added. Eventually this extra error type can retain the input `Bytes`
payload to be re-acquired on error if necessary.
Closes #48
2017-07-28 12:45:54 -07:00
Sean McArthur
56f6b549a3
header: remove inlines from generic methods
2017-07-27 16:40:30 -07:00
Alex Crichton
e1c2d83a12
Add more HttpTryFrom for HeaderName
2017-07-26 14:01:44 -07:00
Alex Crichton
e1d7076019
Fix compile errors with Bytes conversion errors
2017-07-26 14:01:44 -07:00
Eliza Weisman
78bb5dd8f9
Convert from convert::Into into convert::From
2017-07-26 14:01:44 -07:00
Eliza Weisman
1f04392eae
Rewrite fallible conversions to use HttpTryFrom polyfill
2017-07-26 14:01:44 -07:00
Eliza Weisman
820ea810b3
Add convert::From<Bytes> impl to HeaderName
2017-07-26 14:01:44 -07:00
Eliza Weisman
8fe256da0e
Move convert::Into impls to where all the other trait impls are
2017-07-26 14:01:44 -07:00
Eliza Weisman
befc3c0b09
Quick test for StandardHeader::into<Bytes>()
2017-07-26 14:01:44 -07:00
Eliza Weisman
a90dae9780
Add convert::Into impls for HeaderName and HeaderValue
2017-07-26 14:01:44 -07:00
Without Boats
85a0113b37
Rename and coallesce errors.
...
All parsing errors are named `Invalid{Type}`, where Type is the type
being parsed into (e.g. `InvalidMethod`). The same error is returned
regardless of what type the source being parsed was.
2017-07-26 14:01:44 -07:00
Alex Crichton
f34c1d7cc1
Ensure all errors implement Error
2017-07-17 08:50:21 -07:00
Alex Crichton
6bf0a94cb1
Improve compile time of header name parsing
...
A simple test like this previously took about 3 seconds to compile on my
machine:
extern crate http;
fn main() {
use http::HeaderMap;
let mut map = HeaderMap::new();
assert!(map.get("x-hello").is_none());
map.insert("x-hello", "hello");
assert_eq!(map.get("x-hello").unwrap(), &"hello");
map.append("x-hello", "world");
assert_eq!(map.get("x-hello").unwrap(), &"hello");
}
The main problem here was that the `parse_hdr!` macro, which is huge and takes a
long time to compile, was being compiled multiple times locally. There's no need
for this function to get inlined across crates and this PR drops the
compile-time of the above snippet to 0.5s
2017-07-10 13:15:02 -07:00
Carl Lerche
ae9f421746
Add str PartialEq impls for HeaderName ( #33 )
2017-06-15 10:54:29 -07:00
Carl Lerche
01606b1f57
Simplify HeaderMap implementation
...
The previous implementation of `FastHasher`, while fast, resulted in a
high number of collisions. The fast hash function has been switched to
FNV. After making the switch, benchmarks showed that using static hash
values for standard HTTP headers is actually slower than hashing them on
demand with FNV. This is because hashing standard headers only requires
hashing the enum discriminant. Also, benchmarks show that using a
sequential scan map for small header maps isn't really worth it either.
2017-05-01 12:48:11 -07:00
Carl Lerche
cc0c2a04b9
Initial header implementation ( #13 )
...
This PR provides an initial pass at a `header` module. This includes a `HeaderName` and `HeaderMap` implementation.
2017-04-26 16:40:45 -07:00