Skip to content

Commit f60d039

Browse files
committed
Replace st_http::HeaderValue with just bytes
1 parent e637e35 commit f60d039

3 files changed

Lines changed: 13 additions & 40 deletions

File tree

crates/bindings/src/http.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,7 @@ fn convert_request(parts: http::request::Parts) -> st_http::Request {
160160
},
161161
headers: headers
162162
.into_iter()
163-
.map(|(k, v)| {
164-
let v = st_http::HeaderValue {
165-
is_sensitive: v.is_sensitive(),
166-
bytes: v.as_bytes().into(),
167-
};
168-
(k.map(|k| k.to_string()), v)
169-
})
163+
.map(|(k, v)| (k.map(|k| k.as_str().into()), v.as_bytes().into()))
170164
.collect(),
171165
timeout: timeout.map(Into::into),
172166
uri: uri.to_string(),
@@ -195,11 +189,7 @@ fn convert_response(response: st_http::Response) -> http::Result<http::response:
195189
response.status = http::StatusCode::from_u16(code)?;
196190
response.headers = headers
197191
.into_iter()
198-
.map(|(k, v)| {
199-
let mut value = http::HeaderValue::try_from(v.bytes.into_vec())?;
200-
value.set_sensitive(v.is_sensitive);
201-
Ok((k.try_into()?, value))
202-
})
192+
.map(|(k, v)| Ok((k.into_string().try_into()?, v.into_vec().try_into()?)))
203193
.collect::<http::Result<_>>()?;
204194
Ok(response)
205195
}

crates/core/src/host/instance_env.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -701,11 +701,7 @@ fn convert_http_request(request: st_http::Request) -> http::Result<(http::reques
701701
};
702702
request.headers = headers
703703
.into_iter()
704-
.map(|(k, v)| {
705-
let mut value = http::HeaderValue::try_from(v.bytes.into_vec())?;
706-
value.set_sensitive(v.is_sensitive);
707-
Ok((k.try_into()?, value))
708-
})
704+
.map(|(k, v)| Ok((k.into_string().try_into()?, v.into_vec().try_into()?)))
709705
.collect::<http::Result<_>>()?;
710706

711707
let timeout = timeout.map(|d| d.to_duration_saturating());
@@ -729,13 +725,7 @@ fn convert_http_response(response: http::response::Parts) -> st_http::Response {
729725
st_http::Response {
730726
headers: headers
731727
.into_iter()
732-
.map(|(k, v)| {
733-
let v = st_http::HeaderValue {
734-
is_sensitive: v.is_sensitive(),
735-
bytes: v.as_bytes().into(),
736-
};
737-
(k.map(|k| k.to_string()), v)
738-
})
728+
.map(|(k, v)| (k.map(|k| k.as_str().into()), v.as_bytes().into()))
739729
.collect(),
740730
version: match version {
741731
http::Version::HTTP_09 => st_http::Version::Http09,

crates/lib/src/http.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ pub struct Headers {
7676
// `http::header::IntoIter` only returns the `HeaderName` for the first
7777
// `HeaderValue` with that name, so we have to manually assign the names.
7878
struct HeaderIter<I, T> {
79-
prev: Option<(String, T)>,
79+
prev: Option<(Box<str>, T)>,
8080
inner: I,
8181
}
8282

8383
impl<I, T> Iterator for HeaderIter<I, T>
8484
where
85-
I: Iterator<Item = (Option<String>, T)>,
85+
I: Iterator<Item = (Option<Box<str>>, T)>,
8686
{
87-
type Item = (String, T);
87+
type Item = (Box<str>, T);
8888

8989
fn next(&mut self) -> Option<Self::Item> {
9090
let (prev_k, prev_v) = self
@@ -103,8 +103,8 @@ where
103103
}
104104
}
105105

106-
impl FromIterator<(Option<String>, HeaderValue)> for Headers {
107-
fn from_iter<T: IntoIterator<Item = (Option<String>, HeaderValue)>>(iter: T) -> Self {
106+
impl FromIterator<(Option<Box<str>>, Box<[u8]>)> for Headers {
107+
fn from_iter<T: IntoIterator<Item = (Option<Box<str>>, Box<[u8]>)>>(iter: T) -> Self {
108108
let inner = iter.into_iter();
109109
let entries = HeaderIter { prev: None, inner }
110110
.map(|(name, value)| HttpHeaderPair { name, value })
@@ -115,7 +115,7 @@ impl FromIterator<(Option<String>, HeaderValue)> for Headers {
115115

116116
impl Headers {
117117
#[allow(clippy::should_implement_trait)]
118-
pub fn into_iter(self) -> impl Iterator<Item = (String, HeaderValue)> {
118+
pub fn into_iter(self) -> impl Iterator<Item = (Box<str>, Box<[u8]>)> {
119119
IntoIterator::into_iter(self.entries).map(|HttpHeaderPair { name, value }| (name, value))
120120
}
121121
}
@@ -124,16 +124,9 @@ impl Headers {
124124
#[sats(crate = crate, name = "HttpHeaderPair")]
125125
struct HttpHeaderPair {
126126
/// A valid HTTP header name, sourced from an already-validated [`http::HeaderName`].
127-
name: String,
128-
value: HeaderValue,
129-
}
130-
131-
/// A valid HTTP header value, sourced from an already-validated [`http::HeaderValue`].
132-
#[derive(Clone, SpacetimeType)]
133-
#[sats(crate = crate, name = "HttpHeaderValue")]
134-
pub struct HeaderValue {
135-
pub bytes: Box<[u8]>,
136-
pub is_sensitive: bool,
127+
name: Box<str>,
128+
/// A valid HTTP header value, sourced from an already-validated [`http::HeaderValue`].
129+
value: Box<[u8]>,
137130
}
138131

139132
#[derive(Clone, SpacetimeType)]

0 commit comments

Comments
 (0)