-
Notifications
You must be signed in to change notification settings - Fork 799
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: wasix http client: properly forward response headers
Resolves the TODO, and really needed to be done...
- Loading branch information
Showing
1 changed file
with
7 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,18 +34,22 @@ impl ReqwestHttpClient { | |
|
||
let status = response.status().as_u16(); | ||
let status_text = response.status().as_str().to_string(); | ||
// TODO: prevent redundant header copy. | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
theduke
Author
Contributor
|
||
let headers = response | ||
.headers() | ||
.iter() | ||
.map(|(k, v)| (k.to_string(), v.to_str().unwrap().to_string())) | ||
.collect(); | ||
let data = response.bytes().await?.to_vec(); | ||
|
||
// TODO: forward the response headers. | ||
|
||
Ok(HttpResponse { | ||
pos: 0usize, | ||
ok: true, | ||
status, | ||
status_text, | ||
redirected: false, | ||
body: Some(data), | ||
headers: Vec::new(), | ||
headers, | ||
}) | ||
} | ||
} | ||
|
FYI - I don't think this is possible in general because
http::HeaderMap
stores headers as aHashMap<HeaderName, Vec<HeaderValue>>
, but the consuminginto_iter()
will yield(Option<HeaderName>, HeaderValue>
, where you only getSome
for the first occurrence of a particular header.If we are allowed to silently drop/overwrite duplicate headers, then we can implement it without copies.
... Although the
HttpResponse
type'sheaders
field is aVec<(String, String)>
rather than aVec<(HeaderName, HeaderValue)>
, so you'd need to call.to_string()
on things anyway, and we're back where we started.TL;DR: The string copies are annoying, but we'll probably need to keep them if we want to respect HTTP semantics so you can remove the TODO.