This, uh, grew into something far bigger than expected, but it turns out, all of it was needed to eventually support this correctly. - Adds configuration to client and server to set [SETTINGS_MAX_HEADER_LIST_SIZE](http://httpwg.org/specs/rfc7540.html#SETTINGS_MAX_HEADER_LIST_SIZE) - If not set, a "sane default" of 16 MB is used (taken from golang's http2) - Decoding header blocks now happens as they are received, instead of buffering up possibly forever until the last continuation frame is parsed. - As each field is decoded, it's undecoded size is added to the total. Whenever a header block goes over the maximum size, the `frame` will be marked as such. - Whenever a header block is deemed over max limit, decoding will still continue, but new fields will not be appended to `HeaderMap`. This is also can save wasted hashing. - To protect against enormous string literals, such that they span multiple continuation frames, a check is made that the combined encoded bytes is less than the max allowed size. While technically not exactly what the spec suggests (counting decoded size instead), this should hopefully only happen when someone is indeed malicious. If found, a `GOAWAY` of `COMPRESSION_ERROR` is sent, and the connection shut down. - After an oversize header block frame is finished decoding, the streams state machine will notice it is oversize, and handle that. - If the local peer is a server, a 431 response is sent, as suggested by the spec. - A `REFUSED_STREAM` reset is sent, since we cannot actually give the stream to the user. - In order to be able to send both the 431 headers frame, and a reset frame afterwards, the scheduled `Canceled` machinery was made more general to a `Scheduled(Reason)` state instead. Closes #18 Closes #191
68 lines
1.5 KiB
Rust
68 lines
1.5 KiB
Rust
//! Utilities to support tests.
|
|
|
|
#[cfg(not(feature = "unstable"))]
|
|
compile_error!(
|
|
"Tests depend on the 'unstable' feature on h2. \
|
|
Retry with `cargo test --features unstable`"
|
|
);
|
|
|
|
pub extern crate bytes;
|
|
pub extern crate env_logger;
|
|
pub extern crate futures;
|
|
pub extern crate h2;
|
|
pub extern crate http;
|
|
pub extern crate mock_io;
|
|
pub extern crate string;
|
|
pub extern crate tokio_io;
|
|
|
|
// Kind of annoying, but we can't use macros from crates that aren't specified
|
|
// at the root.
|
|
macro_rules! try_ready {
|
|
($e:expr) => ({
|
|
use $crate::support::futures::Async;
|
|
match $e {
|
|
Ok(Async::Ready(t)) => t,
|
|
Ok(Async::NotReady) => return Ok(Async::NotReady),
|
|
Err(e) => return Err(From::from(e)),
|
|
}
|
|
})
|
|
}
|
|
|
|
macro_rules! try_nb {
|
|
($e:expr) => ({
|
|
use $crate::support::futures::Async;
|
|
use ::std::io::ErrorKind::WouldBlock;
|
|
|
|
match $e {
|
|
Ok(t) => t,
|
|
Err(ref e) if e.kind() == WouldBlock => {
|
|
return Ok(Async::NotReady)
|
|
}
|
|
Err(e) => return Err(e.into()),
|
|
}
|
|
})
|
|
}
|
|
|
|
#[macro_use]
|
|
mod assert;
|
|
|
|
#[macro_use]
|
|
pub mod raw;
|
|
|
|
pub mod frames;
|
|
pub mod prelude;
|
|
pub mod mock;
|
|
pub mod notify;
|
|
pub mod util;
|
|
|
|
mod future_ext;
|
|
|
|
pub use self::future_ext::{FutureExt, Unwrap};
|
|
|
|
// This is our test Codec type
|
|
pub type Codec<T> = h2::Codec<T, ::std::io::Cursor<::bytes::Bytes>>;
|
|
|
|
// This is the frame type that is sent
|
|
pub type SendFrame = h2::frame::Frame<::std::io::Cursor<::bytes::Bytes>>;
|
|
|