(
ctx: &Ctx<'_>,
method: &hyper::Method,
uri: &Uri,
headers: Option<&Headers>,
body: Option<&BodyBytes>,
prev_status: &u16,
initial_uri: &Uri,
)
| 165 | } |
| 166 | |
| 167 | fn build_request( |
| 168 | ctx: &Ctx<'_>, |
| 169 | method: &hyper::Method, |
| 170 | uri: &Uri, |
| 171 | headers: Option<&Headers>, |
| 172 | body: Option<&BodyBytes>, |
| 173 | prev_status: &u16, |
| 174 | initial_uri: &Uri, |
| 175 | ) -> Result<Request<BoxBody<Bytes, Infallible>>> { |
| 176 | let same_origin = is_same_origin(uri, initial_uri); |
| 177 | |
| 178 | let change_method = should_change_method(*prev_status, method); |
| 179 | |
| 180 | let (method_to_use, body) = if change_method { |
| 181 | (Method::GET, None) |
| 182 | } else { |
| 183 | (method.clone(), body) |
| 184 | }; |
| 185 | |
| 186 | let mut req = Request::builder().method(method_to_use).uri(uri.clone()); |
| 187 | |
| 188 | let mut detected_headers = HashSet::new(); |
| 189 | |
| 190 | if let Some(headers) = headers { |
| 191 | for (header_name, value) in headers.iter() { |
| 192 | detected_headers.insert(header_name); |
| 193 | if change_method && is_request_body_header_name(header_name) { |
| 194 | continue; |
| 195 | } |
| 196 | if !same_origin && is_cors_non_wildcard_request_header_name(header_name) { |
| 197 | continue; |
| 198 | } |
| 199 | req = req.header(header_name, value) |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | if !detected_headers.contains("user-agent") { |
| 204 | req = req.header("user-agent", ["llrt ", VERSION].concat()); |
| 205 | } |
| 206 | if !detected_headers.contains("accept-encoding") { |
| 207 | req = req.header("accept-encoding", "zstd, br, gzip, deflate"); |
| 208 | } |
| 209 | if !detected_headers.contains("accept") { |
| 210 | req = req.header("accept", "*/*"); |
| 211 | } |
| 212 | req.body(BoxBody::new( |
| 213 | body.map(|b| b.body.clone()).unwrap_or_default(), |
| 214 | )) |
| 215 | .or_throw(ctx) |
| 216 | } |
| 217 | |
| 218 | fn is_same_origin(uri: &Uri, initial_uri: &Uri) -> bool { |
| 219 | is_same_scheme(uri, initial_uri) |
no test coverage detected