(
status: StatusCode,
allowed_origin: Option<&str>,
content_type: Option<&str>,
body: impl Into<Bytes>,
)
| 245 | type CallbackResponse = Response<Full<Bytes>>; |
| 246 | |
| 247 | fn callback_response( |
| 248 | status: StatusCode, |
| 249 | allowed_origin: Option<&str>, |
| 250 | content_type: Option<&str>, |
| 251 | body: impl Into<Bytes>, |
| 252 | ) -> CallbackResponse { |
| 253 | let mut response = Response::new(Full::new(body.into())); |
| 254 | *response.status_mut() = status; |
| 255 | let headers = response.headers_mut(); |
| 256 | if let Some(origin) = allowed_origin { |
| 257 | headers.insert( |
| 258 | ACCESS_CONTROL_ALLOW_ORIGIN, |
| 259 | hyper::header::HeaderValue::from_str(origin).expect("callback origin is valid"), |
| 260 | ); |
| 261 | headers.insert( |
| 262 | ACCESS_CONTROL_ALLOW_METHODS, |
| 263 | hyper::header::HeaderValue::from_static("POST, OPTIONS"), |
| 264 | ); |
| 265 | headers.insert( |
| 266 | ACCESS_CONTROL_ALLOW_HEADERS, |
| 267 | hyper::header::HeaderValue::from_static("Content-Type"), |
| 268 | ); |
| 269 | headers.insert( |
| 270 | ACCESS_CONTROL_MAX_AGE, |
| 271 | hyper::header::HeaderValue::from_static("60"), |
| 272 | ); |
| 273 | headers.insert(VARY, hyper::header::HeaderValue::from_static("Origin")); |
| 274 | } |
| 275 | if let Some(content_type) = content_type { |
| 276 | headers.insert( |
| 277 | CONTENT_TYPE, |
| 278 | hyper::header::HeaderValue::from_str(content_type) |
| 279 | .expect("callback content type is valid"), |
| 280 | ); |
| 281 | } |
| 282 | response |
| 283 | } |
| 284 | |
| 285 | fn empty_response(status: StatusCode, allowed_origin: Option<&str>) -> CallbackResponse { |
| 286 | callback_response(status, allowed_origin, None, Bytes::new()) |
no outgoing calls
no test coverage detected