Skip to content
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
msrv = "1.63.0"
msrv = "1.81.0"
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- nss
- rust-hpke
rust:
- 1.63.0 # MSRV
- 1.81.0 # MSRV
- stable

steps:
Expand Down
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ members = [
"ohttp-client-cli",
"ohttp-server",
]

[workspace.package]
version = "0.6.0"
authors = ["Martin Thomson <mt@lowentropy.net>"]
edition = "2021"
rust-version = "1.81.0"
license = "MIT OR Apache-2.0"
repository = "https://github.com/martinthomson/ohttp"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,4 @@ install itself.

## Minnimum Supported Rust Version (MSRV)

`ohttp` and `bhttp` should compile on Rust 1.63.0.
`ohttp` and `bhttp` should compile on Rust 1.81.0.
12 changes: 8 additions & 4 deletions bhttp-convert/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
[package]
name = "bhttp-convert"
version = "0.5.4"
authors = ["Martin Thomson <mt@lowentropy.net>"]
edition = "2021"
description = "Simple Tool Converting Between HTTP/1.1 and Binary HTTP"
authors.workspace = true
repository.workspace = true
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true

[dependencies]
structopt = "0.3"

[dependencies.bhttp]
path= "../bhttp"
features = ["bhttp", "http"]
features = ["http"]
23 changes: 9 additions & 14 deletions bhttp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
[package]
name = "bhttp"
version = "0.5.4"
authors = ["Martin Thomson <mt@lowentropy.net>"]
edition = "2021"
rust-version = "1.63.0"
license = "MIT OR Apache-2.0"
description = "Binary HTTP messages (RFC 9292)"
repository = "https://github.com/martinthomson/ohttp"
description = "Binary HTTP Messages (RFC 9292)"
authors.workspace = true
repository.workspace = true
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true

[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"]

[dependencies]
thiserror = "1"
Expand Down
8 changes: 1 addition & 7 deletions bhttp/src/err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,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>;
70 changes: 18 additions & 52 deletions bhttp/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,26 @@
#![deny(warnings, clippy::pedantic)]
#![allow(clippy::missing_errors_doc)] // Too lazy to document these.

#[cfg(feature = "read-bhttp")]
use std::convert::TryFrom;
#[cfg(any(
feature = "read-http",
feature = "write-http",
feature = "read-bhttp",
feature = "write-bhttp"
))]
use std::io;

#[cfg(feature = "read-http")]
use std::{convert::TryFrom, io};

#[cfg(feature = "http")]
use url::Url;

mod err;
mod parse;
#[cfg(any(feature = "read-bhttp", feature = "write-bhttp"))]
mod rw;

#[cfg(any(feature = "read-http", feature = "read-bhttp",))]
use std::borrow::BorrowMut;

pub use err::Error;
#[cfg(any(
feature = "read-http",
feature = "write-http",
feature = "read-bhttp",
feature = "write-bhttp"
))]
use err::Res;
#[cfg(feature = "read-http")]
#[cfg(feature = "http")]
use parse::{downcase, is_ows, read_line, split_at, COLON, SEMICOLON, SLASH, SP};
use parse::{index_of, trim_ows, COMMA};
#[cfg(feature = "read-bhttp")]
use rw::{read_varint, read_vec};
#[cfg(feature = "write-bhttp")]
use rw::{write_len, write_varint, write_vec};
use rw::{read_varint, read_vec, write_len, write_varint, write_vec};

#[cfg(feature = "read-http")]
#[cfg(feature = "http")]
const CONTENT_LENGTH: &[u8] = b"content-length";
#[cfg(feature = "read-bhttp")]
const COOKIE: &[u8] = b"cookie";
const TRANSFER_ENCODING: &[u8] = b"transfer-encoding";
const CHUNKED: &[u8] = b"chunked";
Expand Down Expand Up @@ -93,7 +73,6 @@ impl<T> ReadSeek for io::Cursor<T> where T: AsRef<[u8]> {}
impl<T> ReadSeek for io::BufReader<T> where T: io::Read + io::Seek {}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg(any(feature = "read-bhttp", feature = "write-bhttp"))]
pub enum Mode {
KnownLength,
IndeterminateLength,
Expand All @@ -120,7 +99,7 @@ impl Field {
&self.value
}

#[cfg(feature = "write-http")]
#[cfg(feature = "http")]
pub fn write_http(&self, w: &mut impl io::Write) -> Res<()> {
w.write_all(&self.name)?;
w.write_all(b": ")?;
Expand All @@ -129,14 +108,13 @@ impl Field {
Ok(())
}

#[cfg(feature = "write-bhttp")]
pub fn write_bhttp(&self, w: &mut impl io::Write) -> Res<()> {
write_vec(&self.name, w)?;
write_vec(&self.value, w)?;
Ok(())
}

#[cfg(feature = "read-http")]
#[cfg(feature = "http")]
pub fn obs_fold(&mut self, extra: &[u8]) {
self.value.push(SP);
self.value.extend(trim_ows(extra));
Expand Down Expand Up @@ -192,7 +170,7 @@ impl FieldSection {

/// As required by the HTTP specification, remove the Connection header
/// field, everything it refers to, and a few extra fields.
#[cfg(feature = "read-http")]
#[cfg(feature = "http")]
fn strip_connection_headers(&mut self) {
const CONNECTION: &[u8] = b"connection";
const PROXY_CONNECTION: &[u8] = b"proxy-connection";
Expand Down Expand Up @@ -232,7 +210,7 @@ impl FieldSection {
});
}

#[cfg(feature = "read-http")]
#[cfg(feature = "http")]
fn parse_line(fields: &mut Vec<Field>, line: Vec<u8>) -> Res<()> {
// obs-fold is helpful in specs, so support it here too
let f = if is_ows(line[0]) {
Expand All @@ -251,7 +229,7 @@ impl FieldSection {
Ok(())
}

#[cfg(feature = "read-http")]
#[cfg(feature = "http")]
pub fn read_http<T, R>(r: &mut T) -> Res<Self>
where
T: BorrowMut<R> + ?Sized,
Expand All @@ -267,7 +245,6 @@ impl FieldSection {
}
}

#[cfg(feature = "read-bhttp")]
fn read_bhttp_fields<T, R>(terminator: bool, r: &mut T) -> Res<Vec<Field>>
where
T: BorrowMut<R> + ?Sized,
Expand Down Expand Up @@ -302,7 +279,6 @@ impl FieldSection {
}
}

#[cfg(feature = "read-bhttp")]
pub fn read_bhttp<T, R>(mode: Mode, r: &mut T) -> Res<Self>
where
T: BorrowMut<R> + ?Sized,
Expand All @@ -320,15 +296,13 @@ impl FieldSection {
Ok(Self(fields))
}

#[cfg(feature = "write-bhttp")]
fn write_bhttp_headers(&self, w: &mut impl io::Write) -> Res<()> {
for f in &self.0 {
f.write_bhttp(w)?;
}
Ok(())
}

#[cfg(feature = "write-bhttp")]
pub fn write_bhttp(&self, mode: Mode, w: &mut impl io::Write) -> Res<()> {
if mode == Mode::KnownLength {
let mut buf = Vec::new();
Expand All @@ -341,7 +315,7 @@ impl FieldSection {
Ok(())
}

#[cfg(feature = "write-http")]
#[cfg(feature = "http")]
pub fn write_http(&self, w: &mut impl io::Write) -> Res<()> {
for f in &self.0 {
f.write_http(w)?;
Expand Down Expand Up @@ -420,7 +394,7 @@ impl ControlData {
}
}

#[cfg(feature = "read-http")]
#[cfg(feature = "http")]
pub fn read_http(line: Vec<u8>) -> Res<Self> {
// request-line = method SP request-target SP HTTP-version
// status-line = HTTP-version SP status-code SP [reason-phrase]
Expand Down Expand Up @@ -467,7 +441,6 @@ impl ControlData {
}
}

#[cfg(feature = "read-bhttp")]
pub fn read_bhttp<T, R>(request: bool, r: &mut T) -> Res<Self>
where
T: BorrowMut<R> + ?Sized,
Expand All @@ -493,7 +466,6 @@ impl ControlData {
}

/// If this is an informational response.
#[cfg(any(feature = "read-bhttp", feature = "read-http"))]
#[must_use]
fn informational(&self) -> Option<StatusCode> {
match self {
Expand All @@ -502,7 +474,6 @@ impl ControlData {
}
}

#[cfg(feature = "write-bhttp")]
#[must_use]
fn code(&self, mode: Mode) -> u64 {
match (self, mode) {
Expand All @@ -513,7 +484,6 @@ impl ControlData {
}
}

#[cfg(feature = "write-bhttp")]
pub fn write_bhttp(&self, w: &mut impl io::Write) -> Res<()> {
match self {
Self::Request {
Expand All @@ -532,7 +502,7 @@ impl ControlData {
Ok(())
}

#[cfg(feature = "write-http")]
#[cfg(feature = "http")]
pub fn write_http(&self, w: &mut impl io::Write) -> Res<()> {
match self {
Self::Request {
Expand Down Expand Up @@ -581,7 +551,6 @@ impl InformationalResponse {
&self.fields
}

#[cfg(feature = "write-bhttp")]
fn write_bhttp(&self, mode: Mode, w: &mut impl io::Write) -> Res<()> {
write_varint(self.status.code(), w)?;
self.fields.write_bhttp(mode, w)?;
Expand Down Expand Up @@ -662,7 +631,7 @@ impl Message {
&self.trailer
}

#[cfg(feature = "read-http")]
#[cfg(feature = "http")]
fn read_chunked<T, R>(r: &mut T) -> Res<Vec<u8>>
where
T: BorrowMut<R> + ?Sized,
Expand All @@ -686,8 +655,7 @@ impl Message {
}
}

#[cfg(feature = "read-http")]
#[allow(clippy::read_zero_byte_vec)] // https://github.com/rust-lang/rust-clippy/issues/9274
#[cfg(feature = "http")]
pub fn read_http<T, R>(r: &mut T) -> Res<Self>
where
T: BorrowMut<R> + ?Sized,
Expand Down Expand Up @@ -741,7 +709,7 @@ impl Message {
})
}

#[cfg(feature = "write-http")]
#[cfg(feature = "http")]
pub fn write_http(&self, w: &mut impl io::Write) -> Res<()> {
for info in &self.informational {
ControlData::Response(info.status()).write_http(w)?;
Expand Down Expand Up @@ -770,7 +738,6 @@ impl Message {
}

/// Read a BHTTP message.
#[cfg(feature = "read-bhttp")]
pub fn read_bhttp<T, R>(r: &mut T) -> Res<Self>
where
T: BorrowMut<R> + ?Sized,
Expand Down Expand Up @@ -815,7 +782,6 @@ impl Message {
})
}

#[cfg(feature = "write-bhttp")]
pub fn write_bhttp(&self, mode: Mode, w: &mut impl io::Write) -> Res<()> {
write_varint(self.control.code(mode), w)?;
for info in &self.informational {
Expand All @@ -833,7 +799,7 @@ impl Message {
}
}

#[cfg(feature = "write-http")]
#[cfg(feature = "http")]
impl std::fmt::Debug for Message {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
let mut buf = Vec::new();
Expand Down
Loading