qiniu_multipart/server/
tiny_http.rs

1//! Integration with [`tiny_http`](https://github.com/frewsxcv/tiny-http) with the `tiny_http`
2//! feature (optional).
3//!
4//! Contains `impl `[`HttpRequest`](../trait.HttpRequest.html)` for tiny_http::Request` (not shown
5//! here; see [`HttpRequest`'s implementors](../trait.HttpRequest.html#implementors)).
6
7pub use tiny_http::Request as TinyHttpRequest;
8
9use super::HttpRequest;
10
11use std::io::Read;
12
13impl<'r> HttpRequest for &'r mut TinyHttpRequest {
14    type Body = &'r mut dyn Read;
15
16    fn multipart_boundary(&self) -> Option<&str> {
17        const BOUNDARY: &str = "boundary=";
18
19        let content_type = try_opt!(self
20            .headers()
21            .iter()
22            .find(|header| header.field.equiv("Content-Type")))
23        .value
24        .as_str();
25        let start = try_opt!(content_type.find(BOUNDARY)) + BOUNDARY.len();
26        let end = content_type[start..]
27            .find(';')
28            .map_or(content_type.len(), |end| start + end);
29
30        Some(&content_type[start..end])
31    }
32
33    fn body(self) -> Self::Body {
34        self.as_reader()
35    }
36}