[][src]Struct nickel::Response

pub struct Response<'a, D: 'a = (), T: 'static + Any = Fresh> { /* fields omitted */ }

A container for the response

Methods

impl<'a, D> Response<'a, D, Fresh>
[src]

Important traits for Response<'a, D, Streaming>
pub fn from_internal<'c, 'd>(
    response: HyperResponse<'c, Fresh>,
    templates: &'c TemplateCache,
    data: &'c D
) -> Response<'c, D, Fresh>
[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.

Important traits for Response<'a, D, Streaming>
pub fn set<T: Modifier<Response<'a, D>>>(
    &mut self,
    attribute: T
) -> &mut 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
    T: Into<Cow<'static, str>>, 
[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
    H: Header + HeaderFormat,
    F: FnOnce() -> H, 
[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
    T: Serialize,
    P: AsRef<Path> + Into<String>, 
[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
    F: FnMut(&mut Response<'a, D, Fresh>) + 'static, 
[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]

pub fn bail<T>(self, message: T) -> MiddlewareResult<'a, D> where
    T: Into<Cow<'static, str>>, 
[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]

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]

type Result = MiddlewareResult<'a, D>

fn redirect<T>(self, target: T) -> Self::Result where
    T: Into<String>, 
[src]

Redirect the response to a given target Read more

fn redirect_permanently<T>(self, target: T) -> Self::Result where
    T: Into<String>, 
[src]

impl<'a, 'b, D> Write for Response<'a, D, Streaming>
[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> Pluggable for Response<'a, D, T>
[src]

fn get<P>(&mut self) -> Result<<P as Key>::Value, <P as Plugin<Self>>::Error> where
    P: Plugin<Self>,
    Self: Extensible,
    <P as Key>::Value: Clone,
    <P as Key>::Value: Any
[src]

Return a copy of the plugin's produced value. Read more

fn get_ref<P>(
    &mut self
) -> Result<&<P as Key>::Value, <P as Plugin<Self>>::Error> where
    P: Plugin<Self>,
    Self: Extensible,
    <P as Key>::Value: Any
[src]

Return a reference to the plugin's produced value. Read more

fn get_mut<P>(
    &mut self
) -> Result<&mut <P as Key>::Value, <P as Plugin<Self>>::Error> where
    P: Plugin<Self>,
    Self: Extensible,
    <P as Key>::Value: Any
[src]

Return a mutable reference to the plugin's produced value. Read more

fn compute<P>(
    &mut self
) -> Result<<P as Key>::Value, <P as Plugin<Self>>::Error> where
    P: Plugin<Self>, 
[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 MediaType
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for Accept
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for AccessControlAllowHeaders
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for AccessControlAllowMethods
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for AccessControlAllowOrigin
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for AccessControlMaxAge
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for AccessControlRequestHeaders
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for AccessControlRequestMethod
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for AcceptCharset
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for AcceptEncoding
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for AcceptLanguage
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for AcceptRanges
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for Allow
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for Authorization<Basic>
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for Authorization<Bearer>
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for Authorization<String>
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for CacheControl
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for Cookie
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for Connection
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for ContentEncoding
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for ContentLanguage
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for ContentLength
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for ContentType
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for Date
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for ETag
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for Expect
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for Expires
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for From
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for Host
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for IfMatch
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for IfModifiedSince
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for IfNoneMatch
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for IfRange
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for IfUnmodifiedSince
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for LastModified
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for Location
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for Pragma
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for Referer
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for Server
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for SetCookie
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for TransferEncoding
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for Upgrade
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for UserAgent
[src]

impl<'a, D> Modifier<Response<'a, D, Fresh>> for Vary
[src]

Auto Trait Implementations

impl<'a, D = (), T = Fresh> !Send for Response<'a, D, T>

impl<'a, D = (), T = Fresh> !Sync for Response<'a, D, T>

Blanket Implementations

impl<T> From for T
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Typeable for T where
    T: Any

fn get_type(&self) -> TypeId

Get the TypeId of this object.

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
    T: ByteOrder, 

Writes an unsigned 16 bit integer to the underlying writer. Read more

fn write_i16<T>(&mut self, n: i16) -> Result<(), Error> where
    T: ByteOrder, 

Writes a signed 16 bit integer to the underlying writer. Read more

fn write_u24<T>(&mut self, n: u32) -> Result<(), Error> where
    T: ByteOrder, 

Writes an unsigned 24 bit integer to the underlying writer. Read more

fn write_i24<T>(&mut self, n: i32) -> Result<(), Error> where
    T: ByteOrder, 

Writes a signed 24 bit integer to the underlying writer. Read more

fn write_u32<T>(&mut self, n: u32) -> Result<(), Error> where
    T: ByteOrder, 

Writes an unsigned 32 bit integer to the underlying writer. Read more

fn write_i32<T>(&mut self, n: i32) -> Result<(), Error> where
    T: ByteOrder, 

Writes a signed 32 bit integer to the underlying writer. Read more

fn write_u48<T>(&mut self, n: u64) -> Result<(), Error> where
    T: ByteOrder, 

Writes an unsigned 48 bit integer to the underlying writer. Read more

fn write_i48<T>(&mut self, n: i64) -> Result<(), Error> where
    T: ByteOrder, 

Writes a signed 48 bit integer to the underlying writer. Read more

fn write_u64<T>(&mut self, n: u64) -> Result<(), Error> where
    T: ByteOrder, 

Writes an unsigned 64 bit integer to the underlying writer. Read more

fn write_i64<T>(&mut self, n: i64) -> Result<(), Error> where
    T: ByteOrder, 

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
    T: ByteOrder, 

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
    T: ByteOrder, 

Writes a signed n-bytes integer to the underlying writer. Read more

fn write_f32<T>(&mut self, n: f32) -> Result<(), Error> where
    T: ByteOrder, 

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
    T: ByteOrder, 

Writes a IEEE754 double-precision (8 bytes) floating point number to the underlying writer. Read more

impl<T> UnsafeAny for T where
    T: Any