(
mut api_impl: T,
req: (Request<Body>, C),
)
| 199 | |
| 200 | fn call(&mut self, req: (Request<Body>, C)) -> Self::Future { |
| 201 | async fn run<T, C>( |
| 202 | mut api_impl: T, |
| 203 | req: (Request<Body>, C), |
| 204 | ) -> Result<Response<Body>, crate::ServiceError> |
| 205 | where |
| 206 | T: Api<C> + Clone + Send + 'static, |
| 207 | C: Has<XSpanIdString> + Send + Sync + 'static, |
| 208 | { |
| 209 | let (request, context) = req; |
| 210 | let (parts, body) = request.into_parts(); |
| 211 | let (method, uri, headers) = (parts.method, parts.uri, parts.headers); |
| 212 | let path = paths::GLOBAL_REGEX_SET.matches(uri.path()); |
| 213 | |
| 214 | match method { |
| 215 | // ConfigNetworkGet - GET /config/network |
| 216 | hyper::Method::GET if path.matched(paths::ID_CONFIG_NETWORK) => { |
| 217 | let result = api_impl.config_network_get(&context).await; |
| 218 | let mut response = Response::new(Body::empty()); |
| 219 | response.headers_mut().insert( |
| 220 | HeaderName::from_static("x-span-id"), |
| 221 | HeaderValue::from_str( |
| 222 | (&context as &dyn Has<XSpanIdString>) |
| 223 | .get() |
| 224 | .0 |
| 225 | .clone() |
| 226 | .as_str(), |
| 227 | ) |
| 228 | .expect("Unable to create X-Span-ID header value"), |
| 229 | ); |
| 230 | |
| 231 | match result { |
| 232 | Ok(rsp) => match rsp { |
| 233 | ConfigNetworkGetResponse::Success(body) => { |
| 234 | *response.status_mut() = StatusCode::from_u16(200) |
| 235 | .expect("Unable to turn 200 into a StatusCode"); |
| 236 | response.headers_mut().insert( |
| 237 | CONTENT_TYPE, |
| 238 | HeaderValue::from_str("application/json") |
| 239 | .expect("Unable to create Content-Type header for CONFIG_NETWORK_GET_SUCCESS")); |
| 240 | let body_content = serde_json::to_string(&body) |
| 241 | .expect("impossible to fail to serialize"); |
| 242 | *response.body_mut() = Body::from(body_content); |
| 243 | } |
| 244 | }, |
| 245 | Err(_) => { |
| 246 | // Application code returned an error. This should not happen, as the implementation should |
| 247 | // return a valid response. |
| 248 | *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; |
| 249 | *response.body_mut() = Body::from("An internal error occurred"); |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | Ok(response) |
| 254 | } |
| 255 | |
| 256 | // ConfigNetworkOptions - OPTIONS /config/network |
| 257 | hyper::Method::OPTIONS if path.matched(paths::ID_CONFIG_NETWORK) => { |
| 258 | let result = api_impl.config_network_options(&context).await; |
nothing calls this directly
no test coverage detected