Rocket

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit d9bfc9b1040cb81f9db45b0c8116669b03c98c50
parent b5a4e18b0e977041fe96d21bcbc4cf1873bdbf2a
Author: kryptan <kryptan@users.noreply.github.com>
Date:   Sat, 14 Jul 2018 23:48:56 +0300

Implement 'Responder' for '&[u8]'.

Diffstat:
Mcore/lib/src/response/responder.rs | 20+++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/core/lib/src/response/responder.rs b/core/lib/src/response/responder.rs @@ -48,7 +48,14 @@ use request::Request; /// of the response, which is fixed size and not streamed. To stream a /// string, use `Stream::from(Cursor::new(string))`. /// -/// * **Vec<u8>** +/// * **&\[u8\]** +/// +/// Sets the `Content-Type` to `application/octet-stream`. The slice +/// is used as the body of the response, which is fixed size and not +/// streamed. To stream a slice of bytes, use +/// `Stream::from(Cursor::new(data))`. +/// +/// * **Vec&lt;u8>** /// /// Sets the `Content-Type` to `application/octet-stream`. The vector's data /// is used as the body of the response, which is fixed size and not @@ -211,6 +218,17 @@ impl<'r> Responder<'r> for String { /// Returns a response with Content-Type `application/octet-stream` and a /// fixed-size body containing the data in `self`. Always returns `Ok`. +impl<'r> Responder<'r> for &'r [u8] { + fn respond_to(self, _: &Request) -> response::Result<'r> { + Response::build() + .header(ContentType::Binary) + .sized_body(Cursor::new(self)) + .ok() + } +} + +/// Returns a response with Content-Type `application/octet-stream` and a +/// fixed-size body containing the data in `self`. Always returns `Ok`. impl<'r> Responder<'r> for Vec<u8> { fn respond_to(self, _: &Request) -> response::Result<'r> { Response::build()