Skip to main content

multipart_any/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.headers().iter().find(|header| header.field.equiv("Content-Type"))).value.as_str();
20        let start = try_opt!(content_type.find(BOUNDARY)) + BOUNDARY.len();
21        let end = content_type[start..].find(';').map_or(content_type.len(), |end| start + end);
22
23        Some(&content_type[start .. end])
24    }
25
26    fn body(self) -> Self::Body {
27        self.as_reader()
28    }
29}