mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 04:51:22 +00:00
chore: update ext/http to hyper 1.0.1 and http 1.0 (#21588)
Closes https://github.com/denoland/deno/issues/21583.
This commit is contained in:
parent
3fb4f3fe5a
commit
f86456fc26
109
Cargo.lock
generated
109
Cargo.lock
generated
@ -966,7 +966,7 @@ dependencies = [
|
||||
"glibc_version",
|
||||
"glob",
|
||||
"hex",
|
||||
"http",
|
||||
"http 0.2.11",
|
||||
"hyper 0.14.27",
|
||||
"import_map",
|
||||
"indexmap 2.1.0",
|
||||
@ -1254,7 +1254,7 @@ dependencies = [
|
||||
"deno_core",
|
||||
"deno_tls",
|
||||
"dyn-clone",
|
||||
"http",
|
||||
"http 0.2.11",
|
||||
"pin-project",
|
||||
"reqwest",
|
||||
"serde",
|
||||
@ -1336,11 +1336,13 @@ dependencies = [
|
||||
"deno_net",
|
||||
"deno_websocket",
|
||||
"flate2",
|
||||
"http",
|
||||
"http 0.2.11",
|
||||
"http 1.0.0",
|
||||
"http-body-util",
|
||||
"httparse",
|
||||
"hyper 0.14.27",
|
||||
"hyper 1.0.0-rc.4",
|
||||
"hyper 1.1.0",
|
||||
"hyper-util",
|
||||
"itertools",
|
||||
"memmem",
|
||||
"mime",
|
||||
@ -1503,10 +1505,10 @@ dependencies = [
|
||||
"ecb",
|
||||
"elliptic-curve",
|
||||
"errno 0.2.8",
|
||||
"h2",
|
||||
"h2 0.3.22",
|
||||
"hex",
|
||||
"hkdf",
|
||||
"http",
|
||||
"http 0.2.11",
|
||||
"idna 0.3.0",
|
||||
"indexmap 2.1.0",
|
||||
"k256",
|
||||
@ -1615,7 +1617,7 @@ dependencies = [
|
||||
"flate2",
|
||||
"fs3",
|
||||
"fwdansi",
|
||||
"http",
|
||||
"http 0.2.11",
|
||||
"hyper 0.14.27",
|
||||
"libc",
|
||||
"log",
|
||||
@ -1764,8 +1766,8 @@ dependencies = [
|
||||
"deno_net",
|
||||
"deno_tls",
|
||||
"fastwebsockets",
|
||||
"h2",
|
||||
"http",
|
||||
"h2 0.3.22",
|
||||
"http 0.2.11",
|
||||
"hyper 0.14.27",
|
||||
"once_cell",
|
||||
"rustls-tokio-stream",
|
||||
@ -2772,7 +2774,26 @@ dependencies = [
|
||||
"futures-core",
|
||||
"futures-sink",
|
||||
"futures-util",
|
||||
"http",
|
||||
"http 0.2.11",
|
||||
"indexmap 2.1.0",
|
||||
"slab",
|
||||
"tokio",
|
||||
"tokio-util",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "h2"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e1d308f63daf4181410c242d34c11f928dcb3aa105852019e043c9d1f4e4368a"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"fnv",
|
||||
"futures-core",
|
||||
"futures-sink",
|
||||
"futures-util",
|
||||
"http 1.0.0",
|
||||
"indexmap 2.1.0",
|
||||
"slab",
|
||||
"tokio",
|
||||
@ -2919,6 +2940,17 @@ dependencies = [
|
||||
"itoa",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "http"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b32afd38673a8016f7c9ae69e5af41a58f81b1d31689040f2f1959594ce194ea"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"fnv",
|
||||
"itoa",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "http-body"
|
||||
version = "0.4.5"
|
||||
@ -2926,30 +2958,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"http",
|
||||
"http 0.2.11",
|
||||
"pin-project-lite",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "http-body"
|
||||
version = "1.0.0-rc.2"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "951dfc2e32ac02d67c90c0d65bd27009a635dc9b381a2cc7d284ab01e3a0150d"
|
||||
checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"http",
|
||||
"http 1.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "http-body-util"
|
||||
version = "0.1.0-rc.3"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "08ef12f041acdd397010e5fb6433270c147d3b8b2d0a840cd7fff8e531dca5c8"
|
||||
checksum = "41cb79eb393015dadd30fc252023adb0b2400a0caee0fa2a077e6e21a551e840"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"futures-util",
|
||||
"http",
|
||||
"http-body 1.0.0-rc.2",
|
||||
"http 1.0.0",
|
||||
"http-body 1.0.0",
|
||||
"pin-project-lite",
|
||||
]
|
||||
|
||||
@ -2981,8 +3013,8 @@ dependencies = [
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
"futures-util",
|
||||
"h2",
|
||||
"http",
|
||||
"h2 0.3.22",
|
||||
"http 0.2.11",
|
||||
"http-body 0.4.5",
|
||||
"httparse",
|
||||
"httpdate",
|
||||
@ -2997,22 +3029,21 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "hyper"
|
||||
version = "1.0.0-rc.4"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d280a71f348bcc670fc55b02b63c53a04ac0bf2daff2980795aeaf53edae10e6"
|
||||
checksum = "fb5aa53871fc917b1a9ed87b683a5d86db645e23acb32c2e0785a353e522fb75"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"futures-channel",
|
||||
"futures-util",
|
||||
"h2",
|
||||
"http",
|
||||
"http-body 1.0.0-rc.2",
|
||||
"h2 0.4.0",
|
||||
"http 1.0.0",
|
||||
"http-body 1.0.0",
|
||||
"httparse",
|
||||
"httpdate",
|
||||
"itoa",
|
||||
"pin-project-lite",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"want",
|
||||
]
|
||||
|
||||
@ -3023,13 +3054,31 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590"
|
||||
dependencies = [
|
||||
"futures-util",
|
||||
"http",
|
||||
"http 0.2.11",
|
||||
"hyper 0.14.27",
|
||||
"rustls",
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hyper-util"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bdea9aac0dbe5a9240d68cfd9501e2db94222c6dc06843e06640b9e07f0fdc67"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"futures-channel",
|
||||
"futures-util",
|
||||
"http 1.0.0",
|
||||
"http-body 1.0.0",
|
||||
"hyper 1.1.0",
|
||||
"pin-project-lite",
|
||||
"socket2 0.5.5",
|
||||
"tokio",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ident_case"
|
||||
version = "1.0.1"
|
||||
@ -4600,8 +4649,8 @@ dependencies = [
|
||||
"encoding_rs",
|
||||
"futures-core",
|
||||
"futures-util",
|
||||
"h2",
|
||||
"http",
|
||||
"h2 0.3.22",
|
||||
"http 0.2.11",
|
||||
"http-body 0.4.5",
|
||||
"hyper 0.14.27",
|
||||
"hyper-rustls",
|
||||
@ -5913,7 +5962,7 @@ dependencies = [
|
||||
"flate2",
|
||||
"futures",
|
||||
"glob",
|
||||
"h2",
|
||||
"h2 0.3.22",
|
||||
"hyper 0.14.27",
|
||||
"lazy-regex",
|
||||
"libc",
|
||||
|
@ -32,9 +32,11 @@ deno_net.workspace = true
|
||||
deno_websocket.workspace = true
|
||||
flate2.workspace = true
|
||||
http.workspace = true
|
||||
http_1 = { package = "http", version = "=1.0.0" }
|
||||
httparse.workspace = true
|
||||
hyper = { workspace = true, features = ["server", "stream", "http1", "http2", "runtime"] }
|
||||
hyper1 = { package = "hyper", features = ["full"], version = "=1.0.0-rc.4" }
|
||||
hyper-util = { version = "=0.1.2", features = ["tokio"] }
|
||||
hyper1 = { package = "hyper", features = ["full"], version = "=1.1.0" }
|
||||
itertools = "0.10"
|
||||
memmem.workspace = true
|
||||
mime = "0.3.16"
|
||||
@ -52,5 +54,5 @@ tokio-util = { workspace = true, features = ["io"] }
|
||||
|
||||
[dev-dependencies]
|
||||
bencher.workspace = true
|
||||
http-body-util = "=0.1.0-rc.3"
|
||||
http-body-util = "0.1"
|
||||
rand.workspace = true
|
||||
|
@ -3,8 +3,7 @@
|
||||
// Forked from https://github.com/superfly/accept-encoding/blob/1cded757ec7ff3916e5bfe7441db76cdc48170dc/
|
||||
// Forked to support both http 0.3 and http 1.0 crates.
|
||||
|
||||
use http::header::HeaderMap;
|
||||
use http::header::ACCEPT_ENCODING;
|
||||
use http as http_02;
|
||||
use itertools::Itertools;
|
||||
|
||||
/// A list enumerating the categories of errors in this crate.
|
||||
@ -76,13 +75,36 @@ pub fn preferred(
|
||||
}
|
||||
|
||||
/// Parse a set of HTTP headers into an iterator containing tuples of options containing encodings and their corresponding q-values.
|
||||
pub fn encodings_iter(
|
||||
headers: &HeaderMap,
|
||||
///
|
||||
/// Compatible with `http` crate for version 0.2.x.
|
||||
pub fn encodings_iter_http_02(
|
||||
headers: &http_02::HeaderMap,
|
||||
) -> impl Iterator<Item = Result<(Option<Encoding>, f32), EncodingError>> + '_ {
|
||||
headers
|
||||
.get_all(ACCEPT_ENCODING)
|
||||
let iter = headers
|
||||
.get_all(http_02::header::ACCEPT_ENCODING)
|
||||
.iter()
|
||||
.map(|hval| hval.to_str().map_err(|_| EncodingError::InvalidEncoding))
|
||||
.map(|hval| hval.to_str().map_err(|_| EncodingError::InvalidEncoding));
|
||||
encodings_iter_inner(iter)
|
||||
}
|
||||
|
||||
/// Parse a set of HTTP headers into an iterator containing tuples of options containing encodings and their corresponding q-values.
|
||||
///
|
||||
/// Compatible with `http` crate for version 1.x.
|
||||
pub fn encodings_iter_http_1(
|
||||
headers: &http_1::HeaderMap,
|
||||
) -> impl Iterator<Item = Result<(Option<Encoding>, f32), EncodingError>> + '_ {
|
||||
let iter = headers
|
||||
.get_all(http_1::header::ACCEPT_ENCODING)
|
||||
.iter()
|
||||
.map(|hval| hval.to_str().map_err(|_| EncodingError::InvalidEncoding));
|
||||
encodings_iter_inner(iter)
|
||||
}
|
||||
|
||||
/// Parse a set of HTTP headers into an iterator containing tuples of options containing encodings and their corresponding q-values.
|
||||
fn encodings_iter_inner<'s>(
|
||||
headers: impl Iterator<Item = Result<&'s str, EncodingError>> + 's,
|
||||
) -> impl Iterator<Item = Result<(Option<Encoding>, f32), EncodingError>> + 's {
|
||||
headers
|
||||
.map_ok(|s| s.split(',').map(str::trim))
|
||||
.flatten_ok()
|
||||
.filter_map_ok(|v| {
|
||||
@ -104,16 +126,18 @@ pub fn encodings_iter(
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use http::header::ACCEPT_ENCODING;
|
||||
use http::HeaderMap;
|
||||
use http::HeaderValue;
|
||||
|
||||
fn encodings(
|
||||
headers: &HeaderMap,
|
||||
) -> Result<Vec<(Option<Encoding>, f32)>, EncodingError> {
|
||||
encodings_iter(headers).collect()
|
||||
encodings_iter_http_02(headers).collect()
|
||||
}
|
||||
|
||||
fn parse(headers: &HeaderMap) -> Result<Option<Encoding>, EncodingError> {
|
||||
preferred(encodings_iter(headers))
|
||||
preferred(encodings_iter_http_02(headers))
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1,7 +1,6 @@
|
||||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||
use crate::compressible::is_content_compressible;
|
||||
use crate::extract_network_stream;
|
||||
use crate::hyper_util_tokioio::TokioIo;
|
||||
use crate::network_buffered_stream::NetworkStreamPrefixCheck;
|
||||
use crate::request_body::HttpRequestBody;
|
||||
use crate::request_properties::HttpConnectionProperties;
|
||||
@ -44,14 +43,14 @@ use deno_core::ResourceId;
|
||||
use deno_net::ops_tls::TlsStream;
|
||||
use deno_net::raw::NetworkStream;
|
||||
use deno_websocket::ws_create_server_stream;
|
||||
use http::header::ACCEPT_ENCODING;
|
||||
use http::header::CACHE_CONTROL;
|
||||
use http::header::CONTENT_ENCODING;
|
||||
use http::header::CONTENT_LENGTH;
|
||||
use http::header::CONTENT_RANGE;
|
||||
use http::header::CONTENT_TYPE;
|
||||
use http::HeaderMap;
|
||||
use hyper1::body::Incoming;
|
||||
use hyper1::header::HeaderMap;
|
||||
use hyper1::header::ACCEPT_ENCODING;
|
||||
use hyper1::header::CACHE_CONTROL;
|
||||
use hyper1::header::CONTENT_ENCODING;
|
||||
use hyper1::header::CONTENT_LENGTH;
|
||||
use hyper1::header::CONTENT_RANGE;
|
||||
use hyper1::header::CONTENT_TYPE;
|
||||
use hyper1::header::COOKIE;
|
||||
use hyper1::http::HeaderName;
|
||||
use hyper1::http::HeaderValue;
|
||||
@ -60,6 +59,7 @@ use hyper1::server::conn::http2;
|
||||
use hyper1::service::service_fn;
|
||||
use hyper1::service::HttpService;
|
||||
use hyper1::StatusCode;
|
||||
use hyper_util::rt::TokioIo;
|
||||
use once_cell::sync::Lazy;
|
||||
use smallvec::SmallVec;
|
||||
use std::borrow::Cow;
|
||||
@ -567,15 +567,16 @@ fn is_request_compressible(
|
||||
}
|
||||
|
||||
// Fall back to the expensive parser
|
||||
let accepted = fly_accept_encoding::encodings_iter(headers).filter(|r| {
|
||||
matches!(
|
||||
r,
|
||||
Ok((
|
||||
Some(Encoding::Identity | Encoding::Gzip | Encoding::Brotli),
|
||||
_
|
||||
))
|
||||
)
|
||||
});
|
||||
let accepted =
|
||||
fly_accept_encoding::encodings_iter_http_1(headers).filter(|r| {
|
||||
matches!(
|
||||
r,
|
||||
Ok((
|
||||
Some(Encoding::Identity | Encoding::Gzip | Encoding::Brotli),
|
||||
_
|
||||
))
|
||||
)
|
||||
});
|
||||
match fly_accept_encoding::preferred(accepted) {
|
||||
Ok(Some(fly_accept_encoding::Encoding::Gzip)) => Compression::GZip,
|
||||
Ok(Some(fly_accept_encoding::Encoding::Brotli)) => Compression::Brotli,
|
||||
@ -634,7 +635,7 @@ fn modify_compressibility_from_response(
|
||||
/// If the user provided a ETag header for uncompressed data, we need to ensure it is a
|
||||
/// weak Etag header ("W/").
|
||||
fn weaken_etag(hmap: &mut HeaderMap) {
|
||||
if let Some(etag) = hmap.get_mut(hyper::header::ETAG) {
|
||||
if let Some(etag) = hmap.get_mut(hyper1::header::ETAG) {
|
||||
if !etag.as_bytes().starts_with(b"W/") {
|
||||
let mut v = Vec::with_capacity(etag.as_bytes().len() + 2);
|
||||
v.extend(b"W/");
|
||||
@ -649,7 +650,7 @@ fn weaken_etag(hmap: &mut HeaderMap) {
|
||||
// to make sure cache services do not serve uncompressed data to clients that
|
||||
// support compression.
|
||||
fn ensure_vary_accept_encoding(hmap: &mut HeaderMap) {
|
||||
if let Some(v) = hmap.get_mut(hyper::header::VARY) {
|
||||
if let Some(v) = hmap.get_mut(hyper1::header::VARY) {
|
||||
if let Ok(s) = v.to_str() {
|
||||
if !s.to_lowercase().contains("accept-encoding") {
|
||||
*v = format!("Accept-Encoding, {s}").try_into().unwrap()
|
||||
@ -658,7 +659,7 @@ fn ensure_vary_accept_encoding(hmap: &mut HeaderMap) {
|
||||
}
|
||||
}
|
||||
hmap.insert(
|
||||
hyper::header::VARY,
|
||||
hyper1::header::VARY,
|
||||
HeaderValue::from_static("Accept-Encoding"),
|
||||
);
|
||||
}
|
||||
|
@ -1,206 +0,0 @@
|
||||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
// Copyright 2023 Sean McArthur <sean@seanmonstar.com>
|
||||
// MIT licensed copy of unreleased hyper-util code from
|
||||
// https://raw.githubusercontent.com/hyperium/hyper-util/master/src/rt/tokio_io.rs
|
||||
|
||||
#![allow(dead_code)]
|
||||
//! Tokio IO integration for hyper
|
||||
use hyper1 as hyper;
|
||||
use std::pin::Pin;
|
||||
use std::task::Context;
|
||||
use std::task::Poll;
|
||||
|
||||
use pin_project::pin_project;
|
||||
|
||||
/// A wrapping implementing hyper IO traits for a type that
|
||||
/// implements Tokio's IO traits.
|
||||
#[pin_project]
|
||||
#[derive(Debug)]
|
||||
pub struct TokioIo<T> {
|
||||
#[pin]
|
||||
inner: T,
|
||||
}
|
||||
|
||||
impl<T> TokioIo<T> {
|
||||
/// Wrap a type implementing Tokio's IO traits.
|
||||
pub fn new(inner: T) -> Self {
|
||||
Self { inner }
|
||||
}
|
||||
|
||||
/// Borrow the inner type.
|
||||
pub fn inner(&self) -> &T {
|
||||
&self.inner
|
||||
}
|
||||
|
||||
/// Consume this wrapper and get the inner type.
|
||||
pub fn into_inner(self) -> T {
|
||||
self.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> hyper::rt::Read for TokioIo<T>
|
||||
where
|
||||
T: tokio::io::AsyncRead,
|
||||
{
|
||||
fn poll_read(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
mut buf: hyper::rt::ReadBufCursor<'_>,
|
||||
) -> Poll<Result<(), std::io::Error>> {
|
||||
// SAFETY: Imported code from hyper-util
|
||||
let n = unsafe {
|
||||
let mut tbuf = tokio::io::ReadBuf::uninit(buf.as_mut());
|
||||
match tokio::io::AsyncRead::poll_read(self.project().inner, cx, &mut tbuf)
|
||||
{
|
||||
Poll::Ready(Ok(())) => tbuf.filled().len(),
|
||||
other => return other,
|
||||
}
|
||||
};
|
||||
|
||||
// SAFETY: Imported code from hyper-util
|
||||
unsafe {
|
||||
buf.advance(n);
|
||||
}
|
||||
Poll::Ready(Ok(()))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> hyper::rt::Write for TokioIo<T>
|
||||
where
|
||||
T: tokio::io::AsyncWrite,
|
||||
{
|
||||
fn poll_write(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
buf: &[u8],
|
||||
) -> Poll<Result<usize, std::io::Error>> {
|
||||
tokio::io::AsyncWrite::poll_write(self.project().inner, cx, buf)
|
||||
}
|
||||
|
||||
fn poll_flush(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
) -> Poll<Result<(), std::io::Error>> {
|
||||
tokio::io::AsyncWrite::poll_flush(self.project().inner, cx)
|
||||
}
|
||||
|
||||
fn poll_shutdown(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
) -> Poll<Result<(), std::io::Error>> {
|
||||
tokio::io::AsyncWrite::poll_shutdown(self.project().inner, cx)
|
||||
}
|
||||
|
||||
fn is_write_vectored(&self) -> bool {
|
||||
tokio::io::AsyncWrite::is_write_vectored(&self.inner)
|
||||
}
|
||||
|
||||
fn poll_write_vectored(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
bufs: &[std::io::IoSlice<'_>],
|
||||
) -> Poll<Result<usize, std::io::Error>> {
|
||||
tokio::io::AsyncWrite::poll_write_vectored(self.project().inner, cx, bufs)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> tokio::io::AsyncRead for TokioIo<T>
|
||||
where
|
||||
T: hyper::rt::Read,
|
||||
{
|
||||
fn poll_read(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
tbuf: &mut tokio::io::ReadBuf<'_>,
|
||||
) -> Poll<Result<(), std::io::Error>> {
|
||||
//let init = tbuf.initialized().len();
|
||||
let filled = tbuf.filled().len();
|
||||
// SAFETY: Imported code from hyper-util
|
||||
let sub_filled = unsafe {
|
||||
let mut buf = hyper::rt::ReadBuf::uninit(tbuf.unfilled_mut());
|
||||
|
||||
match hyper::rt::Read::poll_read(self.project().inner, cx, buf.unfilled())
|
||||
{
|
||||
Poll::Ready(Ok(())) => buf.filled().len(),
|
||||
other => return other,
|
||||
}
|
||||
};
|
||||
|
||||
let n_filled = filled + sub_filled;
|
||||
// At least sub_filled bytes had to have been initialized.
|
||||
let n_init = sub_filled;
|
||||
// SAFETY: Imported code from hyper-util
|
||||
unsafe {
|
||||
tbuf.assume_init(n_init);
|
||||
tbuf.set_filled(n_filled);
|
||||
}
|
||||
|
||||
Poll::Ready(Ok(()))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> tokio::io::AsyncWrite for TokioIo<T>
|
||||
where
|
||||
T: hyper::rt::Write,
|
||||
{
|
||||
fn poll_write(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
buf: &[u8],
|
||||
) -> Poll<Result<usize, std::io::Error>> {
|
||||
hyper::rt::Write::poll_write(self.project().inner, cx, buf)
|
||||
}
|
||||
|
||||
fn poll_flush(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
) -> Poll<Result<(), std::io::Error>> {
|
||||
hyper::rt::Write::poll_flush(self.project().inner, cx)
|
||||
}
|
||||
|
||||
fn poll_shutdown(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
) -> Poll<Result<(), std::io::Error>> {
|
||||
hyper::rt::Write::poll_shutdown(self.project().inner, cx)
|
||||
}
|
||||
|
||||
fn is_write_vectored(&self) -> bool {
|
||||
hyper::rt::Write::is_write_vectored(&self.inner)
|
||||
}
|
||||
|
||||
fn poll_write_vectored(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
bufs: &[std::io::IoSlice<'_>],
|
||||
) -> Poll<Result<usize, std::io::Error>> {
|
||||
hyper::rt::Write::poll_write_vectored(self.project().inner, cx, bufs)
|
||||
}
|
||||
}
|
||||
|
||||
/// A wrapping implementing Tokio IO traits for a type that
|
||||
/// implements Hyper's IO traits.
|
||||
#[pin_project]
|
||||
#[derive(Debug)]
|
||||
pub struct TokioIoForHyper<T> {
|
||||
#[pin]
|
||||
inner: T,
|
||||
}
|
||||
|
||||
impl<T> TokioIoForHyper<T> {
|
||||
/// Wrap a type implementing Tokio's IO traits.
|
||||
pub fn new(inner: T) -> Self {
|
||||
Self { inner }
|
||||
}
|
||||
|
||||
/// Borrow the inner type.
|
||||
pub fn inner(&self) -> &T {
|
||||
&self.inner
|
||||
}
|
||||
|
||||
/// Consume this wrapper and get the inner type.
|
||||
pub fn into_inner(self) -> T {
|
||||
self.inner
|
||||
}
|
||||
}
|
@ -52,7 +52,7 @@ use hyper::Body;
|
||||
use hyper::HeaderMap;
|
||||
use hyper::Request;
|
||||
use hyper::Response;
|
||||
use hyper_util_tokioio::TokioIo;
|
||||
use hyper_util::rt::TokioIo;
|
||||
use serde::Serialize;
|
||||
use std::borrow::Cow;
|
||||
use std::cell::RefCell;
|
||||
@ -80,7 +80,6 @@ use crate::reader_stream::ShutdownHandle;
|
||||
pub mod compressible;
|
||||
mod fly_accept_encoding;
|
||||
mod http_next;
|
||||
mod hyper_util_tokioio;
|
||||
mod network_buffered_stream;
|
||||
mod reader_stream;
|
||||
mod request_body;
|
||||
@ -221,10 +220,11 @@ impl HttpConnResource {
|
||||
let request = request_rx.await.ok()?;
|
||||
|
||||
let accept_encoding = {
|
||||
let encodings = fly_accept_encoding::encodings_iter(request.headers())
|
||||
.filter(|r| {
|
||||
matches!(r, Ok((Some(Encoding::Brotli | Encoding::Gzip), _)))
|
||||
});
|
||||
let encodings =
|
||||
fly_accept_encoding::encodings_iter_http_02(request.headers())
|
||||
.filter(|r| {
|
||||
matches!(r, Ok((Some(Encoding::Brotli | Encoding::Gzip), _)))
|
||||
});
|
||||
|
||||
fly_accept_encoding::preferred(encodings)
|
||||
.ok()
|
||||
|
@ -8,9 +8,9 @@ use deno_net::raw::NetworkStream;
|
||||
use deno_net::raw::NetworkStreamAddress;
|
||||
use deno_net::raw::NetworkStreamListener;
|
||||
use deno_net::raw::NetworkStreamType;
|
||||
use hyper::HeaderMap;
|
||||
use hyper::Uri;
|
||||
use hyper1::header::HOST;
|
||||
use hyper1::HeaderMap;
|
||||
use hyper1::Uri;
|
||||
use std::borrow::Cow;
|
||||
use std::net::Ipv4Addr;
|
||||
use std::net::SocketAddr;
|
||||
|
@ -14,9 +14,9 @@ use deno_core::AsyncResult;
|
||||
use deno_core::BufView;
|
||||
use deno_core::Resource;
|
||||
use flate2::write::GzEncoder;
|
||||
use http::HeaderMap;
|
||||
use hyper1::body::Frame;
|
||||
use hyper1::body::SizeHint;
|
||||
use hyper1::header::HeaderMap;
|
||||
use pin_project::pin_project;
|
||||
|
||||
/// Simplification for nested types we use for our streams. We provide a way to convert from
|
||||
|
@ -7,12 +7,12 @@ use deno_core::futures::ready;
|
||||
use deno_core::BufView;
|
||||
use deno_core::OpState;
|
||||
use deno_core::ResourceId;
|
||||
use http::request::Parts;
|
||||
use http::HeaderMap;
|
||||
use http_1::request::Parts;
|
||||
use hyper1::body::Body;
|
||||
use hyper1::body::Frame;
|
||||
use hyper1::body::Incoming;
|
||||
use hyper1::body::SizeHint;
|
||||
use hyper1::header::HeaderMap;
|
||||
use hyper1::upgrade::OnUpgrade;
|
||||
|
||||
use scopeguard::guard;
|
||||
@ -209,9 +209,9 @@ pub(crate) async fn handle_request(
|
||||
struct HttpRecordInner {
|
||||
server_state: SignallingRc<HttpServerState>,
|
||||
request_info: HttpConnectionProperties,
|
||||
request_parts: http::request::Parts,
|
||||
request_parts: http_1::request::Parts,
|
||||
request_body: Option<RequestBodyState>,
|
||||
response_parts: Option<http::response::Parts>,
|
||||
response_parts: Option<http_1::response::Parts>,
|
||||
response_ready: bool,
|
||||
response_waker: Option<Waker>,
|
||||
response_body: ResponseBytesInner,
|
||||
@ -244,7 +244,7 @@ impl HttpRecord {
|
||||
) -> Rc<Self> {
|
||||
let (request_parts, request_body) = request.into_parts();
|
||||
let request_body = Some(request_body.into());
|
||||
let (mut response_parts, _) = http::Response::new(()).into_parts();
|
||||
let (mut response_parts, _) = http_1::Response::new(()).into_parts();
|
||||
let record =
|
||||
if let Some((record, headers)) = server_state.borrow_mut().pool.pop() {
|
||||
response_parts.headers = headers;
|
||||
@ -425,7 +425,7 @@ impl HttpRecord {
|
||||
}
|
||||
|
||||
/// Get a mutable reference to the response status and headers.
|
||||
pub fn response_parts(&self) -> RefMut<'_, http::response::Parts> {
|
||||
pub fn response_parts(&self) -> RefMut<'_, http_1::response::Parts> {
|
||||
RefMut::map(self.self_mut(), |inner| {
|
||||
inner.response_parts.as_mut().unwrap()
|
||||
})
|
||||
@ -446,7 +446,7 @@ impl HttpRecord {
|
||||
fn into_response(self: Rc<Self>) -> Response {
|
||||
let parts = self.self_mut().response_parts.take().unwrap();
|
||||
let body = HttpRecordResponse(ManuallyDrop::new(self));
|
||||
http::Response::from_parts(parts, body)
|
||||
Response::from_parts(parts, body)
|
||||
}
|
||||
|
||||
/// Get a reference to the connection properties.
|
||||
@ -590,7 +590,6 @@ impl Drop for HttpRecordResponse {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::hyper_util_tokioio::TokioIo;
|
||||
use crate::response_body::Compression;
|
||||
use crate::response_body::ResponseBytesInner;
|
||||
use bytes::Buf;
|
||||
@ -598,11 +597,12 @@ mod tests {
|
||||
use hyper1::body::Body;
|
||||
use hyper1::service::service_fn;
|
||||
use hyper1::service::HttpService;
|
||||
use hyper_util::rt::TokioIo;
|
||||
use std::error::Error as StdError;
|
||||
|
||||
/// Execute client request on service and concurrently map the response.
|
||||
async fn serve_request<B, S, T, F>(
|
||||
req: http::Request<B>,
|
||||
req: http_1::Request<B>,
|
||||
service: S,
|
||||
map_response: impl FnOnce(hyper1::Response<Incoming>) -> F,
|
||||
) -> hyper1::Result<T>
|
||||
@ -655,7 +655,8 @@ mod tests {
|
||||
)
|
||||
});
|
||||
|
||||
let client_req = http::Request::builder().uri("/").body("".to_string())?;
|
||||
let client_req =
|
||||
http_1::Request::builder().uri("/").body("".to_string())?;
|
||||
|
||||
// Response produced by concurrent tasks
|
||||
tokio::try_join!(
|
||||
|
@ -6,9 +6,9 @@ use bytes::Bytes;
|
||||
use bytes::BytesMut;
|
||||
use deno_core::error::AnyError;
|
||||
use httparse::Status;
|
||||
use hyper::http::HeaderName;
|
||||
use hyper::http::HeaderValue;
|
||||
use hyper::Response;
|
||||
use hyper1::header::HeaderName;
|
||||
use hyper1::header::HeaderValue;
|
||||
use hyper1::Response;
|
||||
use memmem::Searcher;
|
||||
use memmem::TwoWaySearcher;
|
||||
use once_cell::sync::OnceCell;
|
||||
|
Loading…
Reference in New Issue
Block a user