tower_web/response/
file.rs

1use super::{Context, Response, Serializer};
2use error;
3
4use bytes::BytesMut;
5use http::{self, header};
6use tokio_fs::File;
7
8use std::io;
9
10const OCTET_STREAM: &'static str = "application/octet-stream";
11
12impl Response for File {
13    type Buf = io::Cursor<BytesMut>;
14    type Body = error::Map<Self>;
15
16    fn into_http<S: Serializer>(self, context: &Context<S>) -> Result<http::Response<Self::Body>, ::Error> {
17        let content_type = context.content_type_header()
18            .map(|header| header.clone())
19            .unwrap_or_else(|| header::HeaderValue::from_static(OCTET_STREAM));
20
21        Ok(http::Response::builder()
22           .status(200)
23           .header(header::CONTENT_TYPE, content_type)
24           .body(error::Map::new(self))
25           .unwrap())
26    }
27}