Struct nickel::Response [] [src]

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]

[src]

[src]

Get a mutable reference to the status.

[src]

Get a mutable reference to the Headers.

[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'}"
    });

    // ...
}

[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")
}

[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)
}

[src]

Return an error with the appropriate status code for error handlers to provide output for.

[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>"
    });

    // ...
}

[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)
}

[src]

[src]

[src]

[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]

[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.

[src]

Flushes all writing of a response to the client.

impl<'a, D, T: 'static + Any> Response<'a, D, T>
[src]

[src]

The status of this response.

[src]

The headers of this response.

[src]

Trait Implementations

impl<'a, 'b, D> Write for Response<'a, D, Streaming>
[src]

[src]

Write a buffer into this object, returning how many bytes were written. Read more

[src]

Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more

1.0.0
[src]

Attempts to write an entire buffer into this write. Read more

1.0.0
[src]

Writes a formatted string into this writer, returning any error encountered. Read more

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]

[src]

Get a reference to the type's extension storage.

[src]

Get a mutable reference to the type's extension storage.

impl<'a, D, T: 'static + Any> Pluggable for Response<'a, D, T>
[src]

[src]

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

[src]

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

[src]

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

[src]

Create and evaluate a once-off instance of a plugin.

impl<'a, D> Redirect for Response<'a, D>
[src]

[src]

[src]

Redirect the response to a given target Read more

[src]