Skip to content
Merged
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
10 changes: 10 additions & 0 deletions test-programs/src/bin/server_large_body.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use waki::{handler, ErrorCode, Request, Response};

#[handler]
fn hello(_: Request) -> Result<Response, ErrorCode> {
let buffer = [0; 5000];
Response::builder().body(buffer).build()
}

// required since this file is built as a `bin`
fn main() {}
6 changes: 5 additions & 1 deletion waki/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ pub fn handle_response(response_out: ResponseOutparam, response: Response) {
let body = response.body.bytes().unwrap();
if !body.is_empty() {
let out = outgoing_body.write().unwrap();
out.blocking_write_and_flush(&body).unwrap();
// `blocking-write-and-flush` writes up to 4096 bytes
let chunks = body.chunks(4096);
for chunk in chunks {
out.blocking_write_and_flush(chunk).unwrap();
}
}

OutgoingBody::finish(outgoing_body, None).unwrap();
Expand Down
13 changes: 13 additions & 0 deletions waki/tests/all/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ async fn json() -> Result<()> {
Ok(())
}

#[tokio::test(flavor = "multi_thread")]
async fn large_body() -> Result<()> {
let req = hyper::Request::builder()
.uri("http://localhost")
.body(body::empty())?;

let resp = run_wasi_http(test_programs_artifacts::SERVER_LARGE_BODY_COMPONENT, req).await??;
let body = resp.into_body().to_bytes();
assert_eq!(body.len(), 5000);

Ok(())
}

#[tokio::test(flavor = "multi_thread")]
async fn multipart_form() -> Result<()> {
let req = hyper::Request::builder()
Expand Down