Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streamed read for binary HTTP #74

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -3,3 +3,4 @@
*~
*.swp
/.vscode/
/mutants.out*/
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -7,4 +7,5 @@ members = [
"ohttp-client",
"ohttp-client-cli",
"ohttp-server",
"sync-async",
]
2 changes: 1 addition & 1 deletion bhttp-convert/Cargo.toml
Original file line number Diff line number Diff line change
@@ -9,4 +9,4 @@ structopt = "0.3"

[dependencies.bhttp]
path= "../bhttp"
features = ["bhttp", "http"]
features = ["http"]
3 changes: 2 additions & 1 deletion bhttp-convert/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#![deny(warnings, clippy::pedantic)]

use bhttp::{Message, Mode};
use std::{
fs::File,
io::{self, Read},
path::PathBuf,
};

use bhttp::{Message, Mode};
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
15 changes: 8 additions & 7 deletions bhttp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -9,17 +9,18 @@ description = "Binary HTTP messages (RFC 9292)"
repository = "https://github.com/martinthomson/ohttp"

[features]
default = ["bhttp"]
bhttp = ["read-bhttp", "write-bhttp"]
http = ["read-http", "write-http"]
read-bhttp = []
write-bhttp = []
read-http = ["url"]
write-http = []
default = []
http = ["dep:url"]
stream = ["dep:futures", "dep:pin-project"]

[dependencies]
futures = {version = "0.3", optional = true}
pin-project = {version = "1.1", optional = true}
thiserror = "1"
url = {version = "2", optional = true}

[dev-dependencies]
hex = "0.4"

[dev-dependencies.sync-async]
path= "../sync-async"
21 changes: 8 additions & 13 deletions bhttp/src/err.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
use thiserror::Error;

#[derive(Error, Debug)]
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("a request used the CONNECT method")]
ConnectUnsupported,
#[error("a field contained invalid Unicode: {0}")]
CharacterEncoding(#[from] std::string::FromUtf8Error),
#[error("a chunk of data of {0} bytes is too large")]
#[cfg(feature = "stream")]
ChunkTooLarge(u64),
#[error("read a response when expecting a request")]
ExpectedRequest,
#[error("read a request when expecting a response")]
@@ -19,8 +14,14 @@ pub enum Error {
InvalidMode,
#[error("the status code of a response needs to be in 100..=599")]
InvalidStatus,
#[cfg(feature = "stream")]
#[error("a method was called when the message was in the wrong state")]
InvalidState,
#[error("IO error {0}")]
Io(#[from] std::io::Error),
#[cfg(feature = "stream")]
#[error("the size of a vector exceeded the limit that was set")]
LimitExceeded,
#[error("a field or line was missing a necessary character 0x{0:x}")]
Missing(u8),
#[error("a URL was missing a key component")]
@@ -34,14 +35,8 @@ pub enum Error {
#[error("a message included the Upgrade field")]
UpgradeUnsupported,
#[error("a URL could not be parsed into components: {0}")]
#[cfg(feature = "read-http")]
#[cfg(feature = "http")]
UrlParse(#[from] url::ParseError),
}

#[cfg(any(
feature = "read-http",
feature = "write-http",
feature = "read-bhttp",
feature = "write-bhttp"
))]
pub type Res<T> = Result<T, Error>;
Loading