Created
February 5, 2015 07:13
-
-
Save scode/586bf070d5141062be0a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /code fn write_with_body(mut res: HttpResponse<Fresh>, mut body: Box<Reader + Send>) -> IoResult<()> { | |
| let content_type = res.headers().get::<headers::ContentType>() | |
| .map(|cx| cx.clone()) | |
| .unwrap_or_else(|| headers::ContentType("text/plain".parse().unwrap())); | |
| res.headers_mut().set(content_type); | |
| let mut res = try!(res.start()); | |
| // FIXME: Manually inlined old_io::util::copy | |
| // because Box<Reader + Send> does not impl Reader. | |
| // | |
| // Tracking issue: rust-lang/rust#18542 | |
| let mut buf = &mut [0; 1024 * 64]; | |
| loop { | |
| let len = match body.read(buf) { | |
| Ok(len) => len, | |
| Err(ref e) if e.kind == old_io::EndOfFile => break, | |
| Err(e) => { return Err(e) }, | |
| }; | |
| try!(res.write_all(&buf[..len])) | |
| } | |
| res.end() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment