pub struct RequestParts {
pub method: Method,
pub path: String,
pub signing_path: String,
pub query: Option<String>,
pub headers: HeaderMap,
pub form_body: Option<String>,
}Expand description
Owned HTTP request metadata extracted from a web_sys::Request.
Workers passes a web_sys::Request with borrowed JS strings and a
ReadableStream body. The gateway expects a RequestInfo that
borrows from Rust-owned data, so this struct bridges the gap by
owning the parsed method, path, query, and headers.
§Example
let (parts, body) = RequestParts::from_web_sys(&req)?;
let result = gateway
.handle_request(&parts.as_request_info(), body, collect_js_body)
.await;Fields§
§method: MethodThe HTTP method.
path: StringThe percent-decoded URL path (e.g. "/bucket/my key").
Decoded for S3 operation parsing and bucket/key routing. Do not use
this for SigV4 verification: the canonical URI must be the encoded form
the client signed, so use signing_path instead.
signing_path: StringThe raw, percent-encoded URL path exactly as it arrived on the wire
(e.g. "/bucket/my%20key").
This is the form the client signs, so it is what SigV4 verification must
canonicalize over. as_request_info wires it
into RequestInfo’s signing path automatically. Integrators that
rewrite paths before dispatch (e.g. path-mapping) must still sign against
this encoded path — never the decoded path.
query: Option<String>The raw query string, if present.
headers: HeaderMapThe HTTP request headers.
form_body: Option<String>The collected form-encoded body of an
application/x-www-form-urlencoded POST, populated by
absorb_form_body. AWS SDKs send
query-protocol operations (STS AssumeRoleWithWebIdentity) this way,
so without it the STS route handler never sees SDK requests.
Implementations§
Source§impl RequestParts
impl RequestParts
Sourcepub fn from_web_sys(req: &Request) -> Result<(Self, JsBody), String>
pub fn from_web_sys(req: &Request) -> Result<(Self, JsBody), String>
Parse a web_sys::Request into owned request metadata and a
zero-copy JsBody.
Extracts the body stream before reading headers, so the
ReadableStream is never locked.
Sourcepub async fn absorb_form_body(&mut self, body: JsBody) -> Result<JsBody, String>
pub async fn absorb_form_body(&mut self, body: JsBody) -> Result<JsBody, String>
Collect a form-encoded POST body into form_body,
returning an equivalent body to pass on to the gateway.
A no-op passthrough for every other request shape, so integrators can
call it unconditionally between from_web_sys
and dispatch:
let (mut parts, mut body) = RequestParts::from_web_sys(&req)?;
body = parts.absorb_form_body(body).await?;Content-Type is client-controlled, so a form-labeled POST is not
necessarily STS — it could be a mislabeled S3 write
(CompleteMultipartUpload, DeleteObjects). The returned body is
therefore rebuilt from the collected bytes, so a request that falls
through to the S3 pipeline sees its payload unchanged.
Collection is gated on
RequestInfo::should_collect_form_body:
a form POST with a missing or oversized declared Content-Length is
passed through untouched rather than buffered into WASM memory. The
declared length bounds the actual bytes read because Cloudflare’s edge
terminates HTTP — the request stream is derived from message framing,
which cannot deliver more bytes than the declared Content-Length.
Sourcepub fn as_request_info(&self) -> RequestInfo<'_>
pub fn as_request_info(&self) -> RequestInfo<'_>
Borrow this struct as a RequestInfo for gateway dispatch.
Sets the signing path to the raw, percent-encoded
signing_path so SigV4 verification canonicalizes
over the path the client actually signed. Without this, a key containing
a character the client escapes — e.g. a space → %20 — would be verified
against the decoded path and fail with SignatureDoesNotMatch.
Auto Trait Implementations§
impl Freeze for RequestParts
impl RefUnwindSafe for RequestParts
impl Send for RequestParts
impl Sync for RequestParts
impl Unpin for RequestParts
impl UnsafeUnpin for RequestParts
impl UnwindSafe for RequestParts
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more