Skip to content

Commit c8d6569

Browse files
committed
http-compat: add support for convert between bhttp binary and http crate
Signed-off-by: Kun Lai <laikun@linux.alibaba.com>
1 parent 8628e6c commit c8d6569

6 files changed

Lines changed: 1039 additions & 12 deletions

File tree

bhttp/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,24 @@ readme.workspace = true
1616
default = []
1717
http = ["dep:url"]
1818
stream = ["dep:futures", "dep:pin-project"]
19+
http-compat = ["http", "stream", "dep:http", "dep:futures", "dep:http-body", "dep:futures-core", "dep:bytes", "dep:tokio-util", "tokio-util/compat", "tokio-util/io", "dep:tokio", "dep:async-stream"]
1920

2021
[dependencies]
2122
futures = {version = "0.3", optional = true}
2223
pin-project = {version = "1.1", optional = true}
2324
thiserror = "1"
2425
url = {version = "2", optional = true}
26+
bytes = { version = "1.0", optional = true }
27+
futures-core = { version = "0.3.24", optional = true }
28+
http = { version = "1.0", optional = true }
29+
http-body = { version = "1.0", optional = true }
30+
tokio-util = { version = "0.7.16", optional = true }
31+
tokio = { version = "1.47.1", optional = true, default-features = false }
32+
async-stream = { version = "0.3.6", optional = true }
2533

2634
[dev-dependencies]
2735
hex = "0.4"
36+
http-body-util = "0.1"
2837

2938
[dev-dependencies.sync-async]
3039
path= "../sync-async"

bhttp/src/err.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ pub enum Error {
44
ConnectUnsupported,
55
#[error("a field contained invalid Unicode: {0}")]
66
CharacterEncoding(#[from] std::string::FromUtf8Error),
7+
#[error("a field contained invalid Unicode: {0}")]
8+
CharacterEncoding2(#[from] std::str::Utf8Error),
79
#[error("read a response when expecting a request")]
810
ExpectedRequest,
911
#[error("read a request when expecting a response")]
@@ -37,6 +39,18 @@ pub enum Error {
3739
#[error("a URL could not be parsed into components: {0}")]
3840
#[cfg(feature = "http")]
3941
UrlParse(#[from] url::ParseError),
42+
#[error("the status code was not supported {0}")]
43+
#[cfg(feature = "http-compat")]
44+
UnsportedStatusCode(u16),
45+
#[error("got an unknown HTTP body frame type, only data frame and trailer frame are supported")]
46+
#[cfg(feature = "http-compat")]
47+
UnknownHttpBodyFrameType,
48+
#[error("http error")]
49+
#[cfg(feature = "http-compat")]
50+
HttpError(#[from] http::Error),
51+
#[error("http header value contains invalid bytes")]
52+
#[cfg(feature = "http-compat")]
53+
HttpHeaderValueNotString(#[from] http::header::ToStrError),
4054
}
4155

4256
pub type Res<T> = Result<T, Error>;

0 commit comments

Comments
 (0)