(
ctx: &Ctx<'js>,
resource: Value<'js>,
opts: Opt<Value<'js>>,
)
| 680 | fn is_same_host(uri: &Uri, initial_uri: &Uri) -> bool { |
| 681 | uri.host() == initial_uri.host() |
| 682 | } |
| 683 | |
| 684 | fn 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 | |
| 688 | fn 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 | |
| 700 | fn 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 | |
| 707 | fn is_cors_non_wildcard_request_header_name(key: &str) -> bool { |
| 708 | key == AUTHORIZATION |
| 709 | } |
| 710 | |
| 711 | enum 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 | |
| 720 | impl<'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 | |
| 729 | struct 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 |
no test coverage detected