Some improvements to the wasi-http client implementation of write. (#6161)

* Improve write implementation for streams

* Add trailers implementation for responses.

* Improve tests.

* Update tests.
This commit is contained in:
Brendan Burns
2023-04-10 20:26:19 -07:00
committed by GitHub
parent 85f0c68008
commit 3ff6e0fe03
8 changed files with 166 additions and 33 deletions

View File

@@ -8,6 +8,7 @@ use bytes::{BufMut, Bytes, BytesMut};
use http_body_util::{BodyExt, Full};
use hyper::Method;
use hyper::Request;
use std::collections::HashMap;
#[cfg(not(any(target_arch = "riscv64", target_arch = "s390x")))]
use std::sync::Arc;
use std::time::Duration;
@@ -201,6 +202,23 @@ impl WasiHttp {
if let Some(chunk) = frame.data_ref() {
buf.put(chunk.clone());
}
if let Some(trailers) = frame.trailers_ref() {
response.trailers = self.fields_id_base;
self.fields_id_base += 1;
let mut map: HashMap<String, Vec<String>> = HashMap::new();
for (name, value) in trailers.iter() {
let key = name.to_string();
match map.get_mut(&key) {
Some(vec) => vec.push(value.to_str()?.to_string()),
None => {
let mut vec = Vec::new();
vec.push(value.to_str()?.to_string());
map.insert(key, vec);
}
};
}
self.fields.insert(response.trailers, map);
}
}
response.body = self.streams_id_base;
self.streams_id_base = self.streams_id_base + 1;