| 228 | |
| 229 | impl RequestPayloadExt for http::Request<Body> { |
| 230 | fn payload<D>(&self) -> Result<Option<D>, PayloadError> |
| 231 | where |
| 232 | for<'de> D: Deserialize<'de>, |
| 233 | { |
| 234 | self.headers() |
| 235 | .get(http::header::CONTENT_TYPE) |
| 236 | .map(|ct| match ct.to_str() { |
| 237 | Ok(content_type) => { |
| 238 | if content_type.starts_with("application/x-www-form-urlencoded") { |
| 239 | return self.form_url_encoded().map_err(PayloadError::from); |
| 240 | } else if content_type.starts_with("application/json") { |
| 241 | return self.json().map_err(PayloadError::from); |
| 242 | } |
| 243 | Ok(None) |
| 244 | } |
| 245 | _ => Ok(None), |
| 246 | }) |
| 247 | .unwrap_or_else(|| Ok(None)) |
| 248 | } |
| 249 | |
| 250 | fn json<D>(&self) -> Result<Option<D>, JsonPayloadError> |
| 251 | where |