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

Function get_fetch_options

modules/llrt_fetch/src/fetch.rs:682–899  ·  view source on GitHub ↗
(
    ctx: &Ctx<'js>,
    resource: Value<'js>,
    opts: Opt<Value<'js>>,
)

Source from the content-addressed store, hash-verified

680fn is_same_host(uri: &Uri, initial_uri: &Uri) -> bool {
681 uri.host() == initial_uri.host()
682}
683
684fn is_same_port(uri: &Uri, initial_uri: &Uri) -> bool {
685 uri.authority().and_then(|a| a.port()) == initial_uri.authority().and_then(|a| a.port())
686}
687
688fn should_change_method(prev_status: u16, method: &Method) -> bool {
689 if matches!(prev_status, 301 | 302) {
690 return *method == Method::POST;
691 }
692
693 if prev_status == 303 {
694 return !matches!(*method, Method::GET | Method::HEAD);
695 }
696
697 false
698}
699
700fn is_request_body_header_name(key: &str) -> bool {
701 key == CONTENT_ENCODING
702 || key == CONTENT_LANGUAGE
703 || key == CONTENT_LOCATION
704 || key == CONTENT_TYPE
705}
706
707fn is_cors_non_wildcard_request_header_name(key: &str) -> bool {
708 key == AUTHORIZATION
709}
710
711enum RequestBody<'js> {
712 Static {
713 #[allow(dead_code)]
714 object_bytes: ObjectBytes<'js>,
715 body: Full<Bytes>,
716 },
717 Stream(Class<'js, ReadableStream<'js>>),
718}
719
720impl<'js> RequestBody<'js> {
721 fn from_bytes(ctx: Ctx<'js>, object_bytes: ObjectBytes<'js>) -> Result<Self> {
722 //this is safe since we hold on to ObjectBytes
723 let raw_bytes: &'static [u8] = unsafe { std::mem::transmute(object_bytes.as_bytes(&ctx)?) };
724 let body = Full::from(Bytes::from_static(raw_bytes));
725 Ok(Self::Static { object_bytes, body })
726 }
727}
728
729struct FetchOptions<'js> {
730 method: hyper::Method,
731 url: String,
732 headers: Option<Headers>,
733 body: Option<RequestBody<'js>>,
734 abort_receiver: Option<mc_oneshot::Receiver<Value<'js>>>,
735 redirect: String,
736 agent: Option<Class<'js, Agent>>,
737 integrity: Option<String>,
738}
739

Callers 1

initFunction · 0.85

Calls 15

fromFunction · 0.85
StreamFunction · 0.85
as_objectMethod · 0.80
concatMethod · 0.80
okMethod · 0.80
take_body_syncMethod · 0.80
array_buffer_refMethod · 0.80
to_multipart_bytesMethod · 0.80
into_bytesMethod · 0.80
contains_lowerMethod · 0.80
subscribeMethod · 0.80
cloneMethod · 0.45

Tested by

no test coverage detected