[−][src]Struct nickel::Response
A container for the response
Methods
impl<'a, D> Response<'a, D, Fresh>
[src]
impl<'a, D> Response<'a, D, Fresh>
pub fn from_internal<'c, 'd>( | [src] |
pub fn status_mut(&mut self) -> &mut StatusCode | [src] |
Get a mutable reference to the status.
pub fn headers_mut(&mut self) -> &mut Headers | [src] |
Get a mutable reference to the Headers.
pub fn set<T: Modifier<Response<'a, D>>>( | [src] |
Modify the response with the provided data.
Examples
extern crate hyper; #[macro_use] extern crate nickel; use nickel::{Nickel, HttpRouter, MediaType}; use nickel::status::StatusCode; use hyper::header::Location; fn main() { let mut server = Nickel::new(); server.get("/a", middleware! { |_, mut res| // set the Status res.set(StatusCode::PermanentRedirect) // update a Header value .set(Location("http://nickel.rs".into())); "" }); server.get("/b", middleware! { |_, mut res| // setting the content type res.set(MediaType::Json); "{'foo': 'bar'}" }); // ... }
pub fn send<T: Responder<D>>(self, data: T) -> MiddlewareResult<'a, D> | [src] |
Writes a response
Examples
use nickel::{Request, Response, MiddlewareResult}; fn handler<'a, D>(_: &mut Request<D>, res: Response<'a, D>) -> MiddlewareResult<'a, D> { res.send("hello world") }
pub fn send_file<P: AsRef<Path>>(self, path: P) -> MiddlewareResult<'a, D> | [src] |
Writes a file to the output.
Examples
use nickel::{Request, Response, MiddlewareResult}; use std::path::Path; fn handler<'a, D>(_: &mut Request<D>, res: Response<'a, D>) -> MiddlewareResult<'a, D> { let favicon = Path::new("/assets/favicon.ico"); res.send_file(favicon) }
pub fn error<T>(self, status: StatusCode, message: T) -> MiddlewareResult<'a, D> where | [src] |
Return an error with the appropriate status code for error handlers to provide output for.
pub fn set_header_fallback<F, H>(&mut self, f: F) where | [src] |
Sets the header if not already set.
If the header is not set then f
will be called.
Examples
#[macro_use] extern crate nickel; extern crate hyper; use nickel::{Nickel, HttpRouter, MediaType}; use hyper::header::ContentType; fn main() { let mut server = Nickel::new(); server.get("/", middleware! { |_, mut res| res.set(MediaType::Html); res.set_header_fallback(|| { panic!("Should not get called"); ContentType(MediaType::Txt.into()) }); "<h1>Hello World</h1>" }); // ... }
pub fn render<T, P>(self, path: P, data: &T) -> MiddlewareResult<'a, D> where | [src] |
Renders the given template bound with the given data.
Examples
use std::collections::HashMap; use nickel::{Request, Response, MiddlewareResult}; fn handler<'a, D>(_: &mut Request<D>, res: Response<'a, D>) -> MiddlewareResult<'a, D> { let mut data = HashMap::new(); data.insert("name", "user"); res.render("examples/assets/template.tpl", &data) }
pub fn start(self) -> Result<Response<'a, D, Streaming>, NickelError<'a, D>> | [src] |
pub fn server_data(&self) -> &'a D | [src] |
pub fn on_send<F>(&mut self, f: F) where | [src] |
pub fn next_middleware(self) -> MiddlewareResult<'a, D> | [src] |
Pass execution off to another Middleware
When returned from a Middleware, it allows computation to continue in any Middleware queued after the active one.
impl<'a, 'b, D> Response<'a, D, Streaming>
[src]
impl<'a, 'b, D> Response<'a, D, Streaming>
pub fn bail<T>(self, message: T) -> MiddlewareResult<'a, D> where | [src] |
In the case of an unrecoverable error while a stream is already in
progress, there is no standard way to signal to the client that an
error has occurred. bail
will drop the connection and log an error
message.
pub fn end(self) -> Result<()> | [src] |
Flushes all writing of a response to the client.
impl<'a, D, T: 'static + Any> Response<'a, D, T>
[src]
impl<'a, D, T: 'static + Any> Response<'a, D, T>
pub fn status(&self) -> StatusCode | [src] |
The status of this response.
pub fn headers(&self) -> &Headers | [src] |
The headers of this response.
pub fn data(&self) -> &'a D | [src] |
Trait Implementations
impl<'a, D> Redirect for Response<'a, D>
[src]
impl<'a, D> Redirect for Response<'a, D>
type Result = MiddlewareResult<'a, D>
fn redirect_with<T>(self, target: T, status: StatusCode) -> Self::Result where | [src] |
fn redirect<T>(self, target: T) -> Self::Result where | [src] |
Redirect the response to a given target Read more
fn redirect_permanently<T>(self, target: T) -> Self::Result where | [src] |
impl<'a, 'b, D> Write for Response<'a, D, Streaming>
[src]
impl<'a, 'b, D> Write for Response<'a, D, Streaming>
fn write(&mut self, buf: &[u8]) -> Result<usize> | [src] |
fn flush(&mut self) -> Result<()> | [src] |
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error> | 1.0.0 [src] |
Attempts to write an entire buffer into this writer. Read more
fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error> | 1.0.0 [src] |
Writes a formatted string into this writer, returning any error encountered. Read more
fn by_ref(&mut self) -> &mut Self | 1.0.0 [src] |
Creates a "by reference" adaptor for this instance of Write
. Read more
impl<'a, D, T: 'static + Any> Extensible for Response<'a, D, T>
[src]
impl<'a, D, T: 'static + Any> Extensible for Response<'a, D, T>
fn extensions(&self) -> &TypeMap | [src] |
fn extensions_mut(&mut self) -> &mut TypeMap | [src] |
impl<'a, D, T: 'static + Any> Pluggable for Response<'a, D, T>
[src]
impl<'a, D, T: 'static + Any> Pluggable for Response<'a, D, T>
fn get<P>(&mut self) -> Result<<P as Key>::Value, <P as Plugin<Self>>::Error> where | [src] |
Return a copy of the plugin's produced value. Read more
fn get_ref<P>( | [src] |
Return a reference to the plugin's produced value. Read more
fn get_mut<P>( | [src] |
Return a mutable reference to the plugin's produced value. Read more
fn compute<P>( | [src] |
Create and evaluate a once-off instance of a plugin.
impl<'a, D> Modifier<Response<'a, D, Fresh>> for StatusCode
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for StatusCode
impl<'a, D> Modifier<Response<'a, D, Fresh>> for MediaType
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for MediaType
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Accept
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Accept
impl<'a, D> Modifier<Response<'a, D, Fresh>> for AccessControlAllowHeaders
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for AccessControlAllowHeaders
impl<'a, D> Modifier<Response<'a, D, Fresh>> for AccessControlAllowMethods
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for AccessControlAllowMethods
impl<'a, D> Modifier<Response<'a, D, Fresh>> for AccessControlAllowOrigin
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for AccessControlAllowOrigin
impl<'a, D> Modifier<Response<'a, D, Fresh>> for AccessControlMaxAge
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for AccessControlMaxAge
impl<'a, D> Modifier<Response<'a, D, Fresh>> for AccessControlRequestHeaders
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for AccessControlRequestHeaders
impl<'a, D> Modifier<Response<'a, D, Fresh>> for AccessControlRequestMethod
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for AccessControlRequestMethod
impl<'a, D> Modifier<Response<'a, D, Fresh>> for AcceptCharset
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for AcceptCharset
impl<'a, D> Modifier<Response<'a, D, Fresh>> for AcceptEncoding
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for AcceptEncoding
impl<'a, D> Modifier<Response<'a, D, Fresh>> for AcceptLanguage
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for AcceptLanguage
impl<'a, D> Modifier<Response<'a, D, Fresh>> for AcceptRanges
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for AcceptRanges
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Allow
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Allow
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Authorization<Basic>
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Authorization<Basic>
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Authorization<Bearer>
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Authorization<Bearer>
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Authorization<String>
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Authorization<String>
impl<'a, D> Modifier<Response<'a, D, Fresh>> for CacheControl
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for CacheControl
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Cookie
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Cookie
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Connection
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Connection
impl<'a, D> Modifier<Response<'a, D, Fresh>> for ContentEncoding
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for ContentEncoding
impl<'a, D> Modifier<Response<'a, D, Fresh>> for ContentLanguage
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for ContentLanguage
impl<'a, D> Modifier<Response<'a, D, Fresh>> for ContentLength
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for ContentLength
impl<'a, D> Modifier<Response<'a, D, Fresh>> for ContentType
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for ContentType
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Date
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Date
impl<'a, D> Modifier<Response<'a, D, Fresh>> for ETag
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for ETag
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Expect
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Expect
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Expires
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Expires
impl<'a, D> Modifier<Response<'a, D, Fresh>> for From
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for From
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Host
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Host
impl<'a, D> Modifier<Response<'a, D, Fresh>> for IfMatch
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for IfMatch
impl<'a, D> Modifier<Response<'a, D, Fresh>> for IfModifiedSince
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for IfModifiedSince
impl<'a, D> Modifier<Response<'a, D, Fresh>> for IfNoneMatch
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for IfNoneMatch
impl<'a, D> Modifier<Response<'a, D, Fresh>> for IfRange
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for IfRange
impl<'a, D> Modifier<Response<'a, D, Fresh>> for IfUnmodifiedSince
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for IfUnmodifiedSince
impl<'a, D> Modifier<Response<'a, D, Fresh>> for LastModified
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for LastModified
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Location
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Location
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Pragma
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Pragma
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Referer
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Referer
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Server
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Server
impl<'a, D> Modifier<Response<'a, D, Fresh>> for SetCookie
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for SetCookie
impl<'a, D> Modifier<Response<'a, D, Fresh>> for TransferEncoding
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for TransferEncoding
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Upgrade
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Upgrade
impl<'a, D> Modifier<Response<'a, D, Fresh>> for UserAgent
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for UserAgent
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Vary
[src]
impl<'a, D> Modifier<Response<'a, D, Fresh>> for Vary
Auto Trait Implementations
impl<'a, D = (), T = Fresh> !Send for Response<'a, D, T>
impl<'a, D = (), T = Fresh> !Send for Response<'a, D, T>
impl<'a, D = (), T = Fresh> !Sync for Response<'a, D, T>
impl<'a, D = (), T = Fresh> !Sync for Response<'a, D, T>
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error> | [src] |
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId | [src] |
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error> | [src] |
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T | [src] |
impl<T> Typeable for T where
T: Any,
impl<T> Typeable for T where
T: Any,
impl<W> WriteBytesExt for W where
W: Write + ?Sized,
impl<W> WriteBytesExt for W where
W: Write + ?Sized,
fn write_u8(&mut self, n: u8) -> Result<(), Error> |
Writes an unsigned 8 bit integer to the underlying writer. Read more
fn write_i8(&mut self, n: i8) -> Result<(), Error> |
Writes a signed 8 bit integer to the underlying writer. Read more
fn write_u16<T>(&mut self, n: u16) -> Result<(), Error> where |
Writes an unsigned 16 bit integer to the underlying writer. Read more
fn write_i16<T>(&mut self, n: i16) -> Result<(), Error> where |
Writes a signed 16 bit integer to the underlying writer. Read more
fn write_u24<T>(&mut self, n: u32) -> Result<(), Error> where |
Writes an unsigned 24 bit integer to the underlying writer. Read more
fn write_i24<T>(&mut self, n: i32) -> Result<(), Error> where |
Writes a signed 24 bit integer to the underlying writer. Read more
fn write_u32<T>(&mut self, n: u32) -> Result<(), Error> where |
Writes an unsigned 32 bit integer to the underlying writer. Read more
fn write_i32<T>(&mut self, n: i32) -> Result<(), Error> where |
Writes a signed 32 bit integer to the underlying writer. Read more
fn write_u48<T>(&mut self, n: u64) -> Result<(), Error> where |
Writes an unsigned 48 bit integer to the underlying writer. Read more
fn write_i48<T>(&mut self, n: i64) -> Result<(), Error> where |
Writes a signed 48 bit integer to the underlying writer. Read more
fn write_u64<T>(&mut self, n: u64) -> Result<(), Error> where |
Writes an unsigned 64 bit integer to the underlying writer. Read more
fn write_i64<T>(&mut self, n: i64) -> Result<(), Error> where |
Writes a signed 64 bit integer to the underlying writer. Read more
fn write_uint<T>(&mut self, n: u64, nbytes: usize) -> Result<(), Error> where |
Writes an unsigned n-bytes integer to the underlying writer. Read more
fn write_int<T>(&mut self, n: i64, nbytes: usize) -> Result<(), Error> where |
Writes a signed n-bytes integer to the underlying writer. Read more
fn write_f32<T>(&mut self, n: f32) -> Result<(), Error> where |
Writes a IEEE754 single-precision (4 bytes) floating point number to the underlying writer. Read more
fn write_f64<T>(&mut self, n: f64) -> Result<(), Error> where |
Writes a IEEE754 double-precision (8 bytes) floating point number to the underlying writer. Read more
impl<T> UnsafeAny for T where
T: Any,
impl<T> UnsafeAny for T where
T: Any,