MCPcopy Create free account
hub / github.com/awslabs/llrt / form_data

Method form_data

modules/llrt_fetch/src/response.rs:497–531  ·  view source on GitHub ↗
(this: This<Class<'js, Self>>, ctx: Ctx<'js>)

Source from the content-addressed store, hash-verified

495 }
496
497 fn blob(this: This<Class<'js, Self>>, ctx: Ctx<'js>) -> Result<Promise<'js>> {
498 mark_consumed(&this.0);
499 let mime_type = this
500 .0
501 .borrow()
502 .get_header_value(&ctx, CONTENT_TYPE.as_str())?;
503 let class = this.0.clone();
504 let ctx_clone = ctx.clone();
505 Promise::wrap_future(&ctx, async move {
506 let bytes = class
507 .borrow()
508 .take_bytes(&ctx_clone)
509 .await?
510 .unwrap_or_default();
511 Blob::from_bytes(&ctx_clone, bytes, mime_type)
512 })
513 }
514
515 fn form_data(this: This<Class<'js, Self>>, ctx: Ctx<'js>) -> Result<Promise<'js>> {
516 mark_consumed(&this.0);
517 let mime_type = this
518 .0
519 .borrow()
520 .get_header_value(&ctx, CONTENT_TYPE.as_str())?
521 .unwrap_or(MIME_TYPE_OCTET_STREAM.into());
522 let class = this.0.clone();
523 let ctx_clone = ctx.clone();
524 Promise::wrap_future(&ctx, async move {
525 let is_multipart = mime_type.starts_with("multipart/form-data");
526 let is_urlencoded =
527 mime_type.starts_with(MIME_TYPE_FORM_URLENCODED.split(';').next().unwrap_or(""));
528
529 // Consume the body first so stream errors propagate before the
530 // content-type check (matching spec order).
531 let bytes = class.borrow().take_bytes(&ctx_clone).await?;
532
533 if !is_multipart && !is_urlencoded {
534 return Err(Exception::throw_type(

Callers

nothing calls this directly

Calls 6

mark_consumedFunction · 0.85
take_bytesMethod · 0.80
get_header_valueMethod · 0.45
as_strMethod · 0.45
cloneMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected