Skip to content

Commit

Permalink
Merge pull request #175 from technosophos/fix/remove-crs-in-headers-only
Browse files Browse the repository at this point in the history
Remove CRs only in headers
  • Loading branch information
technosophos authored Mar 10, 2022
2 parents 8cff0bf + 9809f88 commit 7f13d8e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub fn compose_response(stdout_mutex: Arc<RwLock<Vec<u8>>>) -> Result<Response<B
let mut out_headers: Vec<u8> = Vec::new();
out.iter().for_each(|i| {
// Ignore CR in headers
if *i == 13 {
if scan_headers && *i == 13 {
return;
} else if scan_headers && *i == 10 && last == 10 {
out_headers.append(&mut buffer);
Expand Down
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ mod test {
#[cfg(target_os = "windows")]
const TEST2_MODULE_MAP_FILE: &str = "test2.toml";
const TEST3_MODULE_MAP_FILE: &str = "test3.toml";
const WAT_MODULE_MAP_FILE: &str = "wat.toml";
const TEST_HEALTHZ_MODULE_MAP_FILE: &str = "test_healthz_override.toml";
const TEST_DYNAMIC_ROUTES_MODULE_MAP_FILE: &str = "test_dynamic_routes.toml";

Expand Down Expand Up @@ -341,6 +342,14 @@ mod test {
}
}

#[tokio::test]
pub async fn can_serve_wat() {
let route = "/";

let response = get_plain_text_response_from_module_map(WAT_MODULE_MAP_FILE, None, route).await;
assert_eq!("Oh hi world\r\n", response);
}

fn parse_ev_line(line: &str) -> Option<(String, String)> {
line.find('=').and_then(|index| {
let left = &line[..index];
Expand Down
20 changes: 20 additions & 0 deletions testdata/module-maps/crlf.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(module
(import "wasi_snapshot_preview1" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32)))
(memory 1)
(export "memory" (memory 0))

(data (i32.const 8) "content-type: text/plain\r\n\r\nOh hi world\r\n")

(func $main (export "_start")
(i32.store (i32.const 0) (i32.const 8))
(i32.store (i32.const 4) (i32.const 41))

(call $fd_write
(i32.const 1)
(i32.const 0)
(i32.const 1)
(i32.const 20)
)
drop
)
)
3 changes: 3 additions & 0 deletions testdata/module-maps/wat.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[[module]]
route = "/"
module = "file:///${PROJECT_ROOT}/testdata/module-maps/crlf.wat"

0 comments on commit 7f13d8e

Please sign in to comment.