Skip to content

Commit

Permalink
Merge branch 'master' of github.com:n1haldev/hyper
Browse files Browse the repository at this point in the history
  • Loading branch information
n1haldev committed Sep 17, 2024
2 parents 8d2c760 + f40754d commit 95184c0
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 26 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ jobs:

- uses: Swatinem/rust-cache@v2

- name: Pin some dependencies
run: |
cargo update -p tokio --precise 1.38.1
cargo update -p tokio-util --precise 0.7.11
- name: Check
run: cargo check --features full

Expand Down Expand Up @@ -201,12 +206,12 @@ jobs:
uses: dtolnay/rust-toolchain@stable

- name: Install cbindgen
uses: taiki-e/cache-cargo-install-action@v1
uses: taiki-e/cache-cargo-install-action@v2
with:
tool: cbindgen

- name: Install cargo-expand
uses: taiki-e/cache-cargo-install-action@v1
uses: taiki-e/cache-cargo-install-action@v2
with:
tool: cargo-expand

Expand Down Expand Up @@ -250,7 +255,7 @@ jobs:
toolchain: nightly-2024-05-01 # Compatible version for cargo-check-external-types

- name: Install cargo-check-external-types
uses: taiki-e/cache-cargo-install-action@v1
uses: taiki-e/cache-cargo-install-action@v2
with:
tool: [email protected]

Expand Down
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ Be sure to check out the [upgrading guide](https://hyper.rs/guides/1/upgrading).

#### Breaking Changes

* Any IO transport type provided must not implement `hyper::rt::{Read, Write}` instead of
* Any IO transport type provided must now implement `hyper::rt::{Read, Write}` instead of
`tokio::io` traits. You can grab a helper type from `hyper-util` to wrap Tokio types, or implement the traits yourself,
if it's a custom type.
([f9f65b7a](https://github.com/hyperium/hyper/commit/f9f65b7aa67fa3ec0267fe015945973726285bc2))
Expand Down Expand Up @@ -1600,7 +1600,7 @@ Be sure to check out the [upgrading guide](https://hyper.rs/guides/1/upgrading).

* **client:**
* check for dead connections in Pool ([44af2738](https://github.com/hyperium/hyper/commit/44af273853f82b81591b813d13627e143a14a6b7), closes [#1429](https://github.com/hyperium/hyper/issues/1429))
* error on unsupport 101 responses, ignore other 1xx codes ([22774222](https://github.com/hyperium/hyper/commit/227742221fa7830a14c18becbbc6137d97b57729))
* error on unsupported 101 responses, ignore other 1xx codes ([22774222](https://github.com/hyperium/hyper/commit/227742221fa7830a14c18becbbc6137d97b57729))
* **server:**
* send 400 responses on parse errors before closing connection ([7cb72d20](https://github.com/hyperium/hyper/commit/7cb72d2019bffbc667b9ad2d8cbc19c1a513fcf7))
* error if Response code is 1xx ([44c34ce9](https://github.com/hyperium/hyper/commit/44c34ce9adc888916bd67656cc54c35f7908f536))
Expand Down
6 changes: 3 additions & 3 deletions capi/include/hyper.h
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ void hyper_waker_free(struct hyper_waker *waker);
void hyper_waker_wake(struct hyper_waker *waker);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
} // extern "C"
#endif // __cplusplus

#endif /* _HYPER_H */
#endif /* _HYPER_H */
2 changes: 2 additions & 0 deletions src/client/conn/http1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ pub struct Parts<T> {
///
/// In most cases, this should just be spawned into an executor, so that it
/// can process incoming and outgoing messages, notice hangups, and the like.
///
/// Instances of this type are typically created via the [`handshake`] function
#[must_use = "futures do nothing unless polled"]
pub struct Connection<T, B>
where
Expand Down
50 changes: 44 additions & 6 deletions src/client/conn/http2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ impl<B> Clone for SendRequest<B> {
///
/// In most cases, this should just be spawned into an executor, so that it
/// can process incoming and outgoing messages, notice hangups, and the like.
///
/// Instances of this type are typically created via the [`handshake`] function
#[must_use = "futures do nothing unless polled"]
pub struct Connection<T, B, E>
where
Expand Down Expand Up @@ -337,13 +339,9 @@ where

/// Sets the maximum frame size to use for HTTP2.
///
/// Passing `None` will do nothing.
///
/// If not set, hyper will use a default.
/// Default is currently 16KB, but can change.
pub fn max_frame_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
if let Some(sz) = sz.into() {
self.h2_builder.max_frame_size = sz;
}
self.h2_builder.max_frame_size = sz.into();
self
}

Expand All @@ -355,6 +353,46 @@ where
self
}

/// Sets the header table size.
///
/// This setting informs the peer of the maximum size of the header compression
/// table used to encode header blocks, in octets. The encoder may select any value
/// equal to or less than the header table size specified by the sender.
///
/// The default value of crate `h2` is 4,096.
pub fn header_table_size(&mut self, size: impl Into<Option<u32>>) -> &mut Self {
self.h2_builder.header_table_size = size.into();
self
}

/// Sets the maximum number of concurrent streams.
///
/// The maximum concurrent streams setting only controls the maximum number
/// of streams that can be initiated by the remote peer. In other words,
/// when this setting is set to 100, this does not limit the number of
/// concurrent streams that can be created by the caller.
///
/// It is recommended that this value be no smaller than 100, so as to not
/// unnecessarily limit parallelism. However, any value is legal, including
/// 0. If `max` is set to 0, then the remote will not be permitted to
/// initiate streams.
///
/// Note that streams in the reserved state, i.e., push promises that have
/// been reserved but the stream has not started, do not count against this
/// setting.
///
/// Also note that if the remote *does* exceed the value set here, it is not
/// a protocol level error. Instead, the `h2` library will immediately reset
/// the stream.
///
/// See [Section 5.1.2] in the HTTP/2 spec for more details.
///
/// [Section 5.1.2]: https://http2.github.io/http2-spec/#rfc.section.5.1.2
pub fn max_concurrent_streams(&mut self, max: impl Into<Option<u32>>) -> &mut Self {
self.h2_builder.max_concurrent_streams = max.into();
self
}

/// Sets an interval for HTTP2 Ping frames should be sent to keep a
/// connection alive.
///
Expand Down
2 changes: 1 addition & 1 deletion src/client/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub(crate) type Promise<T> = oneshot::Receiver<Result<T, crate::Error>>;

/// An error when calling `try_send_request`.
///
/// There is a possibility of an error occuring on a connection in-between the
/// There is a possibility of an error occurring on a connection in-between the
/// time that a request is queued and when it is actually written to the IO
/// transport. If that happens, it is safe to return the request back to the
/// caller, as it was never fully sent.
Expand Down
2 changes: 1 addition & 1 deletion src/ext/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl OriginalHeaderOrder {
}

// No doc test is run here because `RUSTFLAGS='--cfg hyper_unstable_ffi'`
// is needed to compile. Once ffi is stablized `no_run` should be removed
// is needed to compile. Once ffi is stabilized `no_run` should be removed
// here.
/// This returns an iterator that provides header names and indexes
/// in the original order received.
Expand Down
5 changes: 5 additions & 0 deletions src/proto/h1/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ where
self.state.allow_half_close = true;
}

#[cfg(feature = "server")]
pub(crate) fn disable_date_header(&mut self) {
self.state.date_header = false;
}

pub(crate) fn into_inner(self) -> (I, Bytes) {
self.io.into_inner()
}
Expand Down
21 changes: 18 additions & 3 deletions src/proto/h2/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,16 @@ pub(crate) struct Config {
pub(crate) initial_conn_window_size: u32,
pub(crate) initial_stream_window_size: u32,
pub(crate) initial_max_send_streams: usize,
pub(crate) max_frame_size: u32,
pub(crate) max_frame_size: Option<u32>,
pub(crate) max_header_list_size: u32,
pub(crate) keep_alive_interval: Option<Duration>,
pub(crate) keep_alive_timeout: Duration,
pub(crate) keep_alive_while_idle: bool,
pub(crate) max_concurrent_reset_streams: Option<usize>,
pub(crate) max_send_buffer_size: usize,
pub(crate) max_pending_accept_reset_streams: Option<usize>,
pub(crate) header_table_size: Option<u32>,
pub(crate) max_concurrent_streams: Option<u32>,
}

impl Default for Config {
Expand All @@ -85,14 +87,16 @@ impl Default for Config {
initial_conn_window_size: DEFAULT_CONN_WINDOW,
initial_stream_window_size: DEFAULT_STREAM_WINDOW,
initial_max_send_streams: DEFAULT_INITIAL_MAX_SEND_STREAMS,
max_frame_size: DEFAULT_MAX_FRAME_SIZE,
max_frame_size: Some(DEFAULT_MAX_FRAME_SIZE),
max_header_list_size: DEFAULT_MAX_HEADER_LIST_SIZE,
keep_alive_interval: None,
keep_alive_timeout: Duration::from_secs(20),
keep_alive_while_idle: false,
max_concurrent_reset_streams: None,
max_send_buffer_size: DEFAULT_MAX_SEND_BUF_SIZE,
max_pending_accept_reset_streams: None,
header_table_size: None,
max_concurrent_streams: None,
}
}
}
Expand All @@ -103,16 +107,24 @@ fn new_builder(config: &Config) -> Builder {
.initial_max_send_streams(config.initial_max_send_streams)
.initial_window_size(config.initial_stream_window_size)
.initial_connection_window_size(config.initial_conn_window_size)
.max_frame_size(config.max_frame_size)
.max_header_list_size(config.max_header_list_size)
.max_send_buffer_size(config.max_send_buffer_size)
.enable_push(false);
if let Some(max) = config.max_frame_size {
builder.max_frame_size(max);
}
if let Some(max) = config.max_concurrent_reset_streams {
builder.max_concurrent_reset_streams(max);
}
if let Some(max) = config.max_pending_accept_reset_streams {
builder.max_pending_accept_reset_streams(max);
}
if let Some(size) = config.header_table_size {
builder.header_table_size(size);
}
if let Some(max) = config.max_concurrent_streams {
builder.max_concurrent_streams(max);
}
builder
}

Expand Down Expand Up @@ -722,6 +734,9 @@ where
}

Poll::Pending => match ready!(Pin::new(&mut self.conn_eof).poll(cx)) {
// As of Rust 1.82, this pattern is no longer needed, and emits a warning.
// But we cannot remove it as long as MSRV is less than that.
#[allow(unused)]
Ok(never) => match never {},
Err(_conn_is_eof) => {
trace!("connection task is closed, closing dispatch task");
Expand Down
7 changes: 7 additions & 0 deletions src/proto/h2/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,13 @@ where
me.reply.send_reset(h2::Reason::INTERNAL_ERROR);
return Poll::Ready(Err(crate::Error::new_user_header()));
}
if res
.headers_mut()
.remove(::http::header::CONTENT_LENGTH)
.is_some()
{
warn!("successful response to CONNECT request disallows content-length header");
}
let send_stream = reply!(me, res, false);
connect_parts.pending.fulfill(Upgraded::new(
H2Upgraded {
Expand Down
22 changes: 16 additions & 6 deletions src/rt/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,19 +244,29 @@ impl<'data> ReadBufCursor<'data> {
self.buf.init = self.buf.filled.max(self.buf.init);
}

/// Returns the number of bytes that can be written from the current
/// position until the end of the buffer is reached.
///
/// This value is equal to the length of the slice returned by `as_mut()``.
#[inline]
pub(crate) fn remaining(&self) -> usize {
pub fn remaining(&self) -> usize {
self.buf.remaining()
}

/// Transfer bytes into `self`` from `src` and advance the cursor
/// by the number of bytes written.
///
/// # Panics
///
/// `self` must have enough remaining capacity to contain all of `src`.
#[inline]
pub(crate) fn put_slice(&mut self, buf: &[u8]) {
pub fn put_slice(&mut self, src: &[u8]) {
assert!(
self.buf.remaining() >= buf.len(),
"buf.len() must fit in remaining()"
self.buf.remaining() >= src.len(),
"src.len() must fit in remaining()"
);

let amt = buf.len();
let amt = src.len();
// Cannot overflow, asserted above
let end = self.buf.filled + amt;

Expand All @@ -265,7 +275,7 @@ impl<'data> ReadBufCursor<'data> {
self.buf.raw[self.buf.filled..end]
.as_mut_ptr()
.cast::<u8>()
.copy_from_nonoverlapping(buf.as_ptr(), amt);
.copy_from_nonoverlapping(src.as_ptr(), amt);
}

if self.buf.init < end {
Expand Down
2 changes: 1 addition & 1 deletion src/rt/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
//! self.project().inner.as_mut().reset(deadline.into());
//! }
//! }
//! ````
//! ```

use std::{
any::TypeId,
Expand Down
3 changes: 3 additions & 0 deletions src/server/conn/http1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,9 @@ impl Builder {
if let Some(max) = self.max_buf_size {
conn.set_max_buf_size(max);
}
if !self.date_header {
conn.disable_date_header();
}
let sd = proto::h1::dispatch::Server::new(service);
let proto = proto::h1::Dispatcher::new(sd, conn);
Connection { conn: proto }
Expand Down
5 changes: 5 additions & 0 deletions src/service/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ pub trait Service<Request> {
type Response;

/// Errors produced by the service.
///
/// Note: Returning an `Error` to a hyper server, the behavior depends on the
/// protocol. In most cases, hyper will cause the connection to be abruptly aborted.
/// It will abort the request however the protocol allows, either with some sort of RST_STREAM,
/// or killing the connection if that doesn't exist.
type Error;

/// The future response value.
Expand Down

0 comments on commit 95184c0

Please sign in to comment.