From 304c35e0555effde91d56235ad70c01455688ac1 Mon Sep 17 00:00:00 2001 From: max-lt Date: Sun, 24 Mar 2024 21:04:23 +0100 Subject: [PATCH] Handle request body --- src/ext/event_fetch.js | 5 ++++- src/ext/event_fetch.rs | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/ext/event_fetch.js b/src/ext/event_fetch.js index 29b60d1..9315952 100644 --- a/src/ext/event_fetch.js +++ b/src/ext/event_fetch.js @@ -4,6 +4,7 @@ import { guardFromHeaders, headersFromHeaderList, } from "ext:deno_fetch/20_headers.js"; +import { extractBody } from "ext:deno_fetch/22_body.js"; import { newInnerRequest, fromInnerRequest, @@ -31,11 +32,13 @@ function triggerFetchEvent(rid) { const signal = newSignal(); + const { body } = extractBody(evt.req.body); + const inner = newInnerRequest( evt.req.method, evt.req.url, () => evt.req.headers, - evt.req.body + body ); const guard = guardFromHeaders(headersFromHeaderList(inner.headerList)); diff --git a/src/ext/event_fetch.rs b/src/ext/event_fetch.rs index fcfecd2..4922ae4 100644 --- a/src/ext/event_fetch.rs +++ b/src/ext/event_fetch.rs @@ -83,7 +83,7 @@ struct InnerRequest { method: String, url: String, headers: Vec<(String, String)>, - body: Option, + body: Option, } #[derive(Debug, Serialize)] @@ -102,7 +102,10 @@ impl From for InnerRequest { .iter() .map(|(k, v)| (k.to_string(), v.to_str().unwrap().to_string())) .collect(), - body: None, + body: match req.body().len() { + 0 => None, + _ => Some(req.body().to_owned()) + } } } }