Struct http_stub::HttpStub [] [src]

pub struct HttpStub<'a, 'b, 'c> {
    // some fields omitted
}

The entry point. Associated functions can create new servers, instances can make assertions and return headers, status and a body.

Methods

impl<'a, 'b, 'c> HttpStub<'a, 'b, 'c>

fn run<F>(spec: F) -> String where F: Fn(HttpStub) + Send + Sync + 'static

Start a new server, on a port above 3000. Returns a string with the server url, for example: text http://127.0.0.1:3000

fn got_method(&self, method: Method)

Assert request's method matches the expected Method.

fn got_path(&self, path: &str)

Assert request's path matches your expectation.

fn got_header(&self, header_name: &str, value: &str)

Assert request's header "header_name" matches the given "value". Value is compiled as a regex so you can provide a pattern.

fn got_body(&self, value: &str)

Assert request's body contains the given value. Value is compiled as a regex so you can provide a pattern.

fn send_status(&mut self, status: StatusCode)

Respond with the given StatusCode

fn send_header<H: Header + HeaderFormat>(&mut self, header: H)

Add a header to the response. (Call as many times as you want).

fn send_body(self, body: &str)

Sends the response and closes the stream. Pass an empty string for an empty body. It's mandatory to send a body with your response and it should be the last thing you do with your HttpStub.