Skip to content

Commit d28e4ca

Browse files
committed
re-export HeaderMap, HeaderName, HeaderValue under their names from http crate
and get rid of the aliases. this crate doesnt even expose trailers, when we do it can just be a method called trailers(&self) -> &HeaderMap, no big deal.
1 parent 5e2ce16 commit d28e4ca

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

src/http/fields.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
1-
pub use http::header::{HeaderMap as Fields, HeaderName as FieldName, HeaderValue as FieldValue};
2-
pub type Headers = Fields;
3-
pub type Trailers = Fields;
1+
pub use http::header::{HeaderMap, HeaderName, HeaderValue};
42

53
use super::{Error, Result};
6-
use wasi::http::types::Fields as WasiFields;
4+
use wasi::http::types::Fields;
75

8-
pub(crate) fn fields_from_wasi(wasi_fields: WasiFields) -> Result<Fields> {
9-
let mut output = Fields::new();
6+
pub(crate) fn header_map_from_wasi(wasi_fields: Fields) -> Result<HeaderMap> {
7+
let mut output = HeaderMap::new();
108
for (key, value) in wasi_fields.entries() {
11-
let key = FieldName::from_bytes(key.as_bytes())
9+
let key = HeaderName::from_bytes(key.as_bytes())
1210
.map_err(|e| Error::from(e).context("header name {key}"))?;
13-
let value = FieldValue::from_bytes(&value)
11+
let value = HeaderValue::from_bytes(&value)
1412
.map_err(|e| Error::from(e).context("header value for {key}"))?;
1513
output.append(key, value);
1614
}
1715
Ok(output)
1816
}
1917

20-
pub(crate) fn fields_to_wasi(fields: &Fields) -> Result<WasiFields> {
21-
let wasi_fields = WasiFields::new();
22-
for (key, value) in fields {
18+
#[allow(dead_code)]
19+
pub(crate) fn header_map_to_wasi(header_map: &HeaderMap) -> Result<Fields> {
20+
let wasi_fields = Fields::new();
21+
for (key, value) in header_map {
2322
wasi_fields
2423
.append(&key.as_str().to_owned(), &value.as_bytes().to_owned())
2524
.map_err(|e| Error::from(e).context("header named {key}"))?;

src/http/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ pub use http::uri::Uri;
66
pub use body::{Body, IntoBody};
77
pub use client::Client;
88
pub use error::{Error, Result};
9-
pub use fields::{FieldName, FieldValue, Fields, Headers, Trailers};
9+
pub use fields::{HeaderMap, HeaderName, HeaderValue};
1010
pub use method::Method;
1111
pub use request::Request;
1212
pub use response::Response;
1313
pub use status_code::StatusCode;
1414

15-
pub(crate) use fields::fields_from_wasi;
15+
pub(crate) use fields::header_map_from_wasi;
1616

1717
pub mod body;
1818

src/http/response.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use wasi::http::types::{IncomingBody as WasiIncomingBody, IncomingResponse};
22
use wasi::io::streams::{InputStream, StreamError};
33

4-
use super::{fields_from_wasi, Body, Headers, StatusCode};
4+
use super::{header_map_from_wasi, Body, HeaderMap, StatusCode};
55
use crate::io::AsyncRead;
66
use crate::runtime::Reactor;
77

@@ -11,7 +11,7 @@ const CHUNK_SIZE: u64 = 2048;
1111
/// An HTTP response
1212
#[derive(Debug)]
1313
pub struct Response<B: Body> {
14-
headers: Headers,
14+
headers: HeaderMap,
1515
status: StatusCode,
1616
body: B,
1717
}
@@ -46,7 +46,7 @@ pub struct Response<B: Body> {
4646

4747
impl Response<IncomingBody> {
4848
pub(crate) fn try_from_incoming_response(incoming: IncomingResponse) -> super::Result<Self> {
49-
let headers: Headers = fields_from_wasi(incoming.headers())?;
49+
let headers: HeaderMap = header_map_from_wasi(incoming.headers())?;
5050
let status = incoming.status().into();
5151

5252
// `body_stream` is a child of `incoming_body` which means we cannot
@@ -80,12 +80,12 @@ impl<B: Body> Response<B> {
8080
}
8181

8282
/// Get the HTTP headers from the impl
83-
pub fn headers(&self) -> &Headers {
83+
pub fn headers(&self) -> &HeaderMap {
8484
&self.headers
8585
}
8686

8787
/// Mutably get the HTTP headers from the impl
88-
pub fn headers_mut(&mut self) -> &mut Headers {
88+
pub fn headers_mut(&mut self) -> &mut HeaderMap {
8989
&mut self.headers
9090
}
9191

0 commit comments

Comments
 (0)