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