Struct rocket::local::blocking::Client[][src]

pub struct Client { /* fields omitted */ }
Expand description

A blocking client to construct and dispatch local requests.

For details, see the top-level documentation. For the async version, see asynchronous::Client.

Example

The following snippet creates a Client from a Rocket instance and dispatches a local POST / request with a body of Hello, world!.

use rocket::local::blocking::Client;

let rocket = rocket::build();
let client = Client::tracked(rocket).expect("valid rocket");
let response = client.post("/")
    .body("Hello, world!")
    .dispatch();

Implementations

impl Client[src]

pub fn tracked<P: Phase>(rocket: Rocket<P>) -> Result<Self, Error>[src]

Construct a new Client from an instance of Rocket with cookie tracking. This is typically the desired mode of operation for testing.

Cookie Tracking

With cookie tracking enabled, a Client propagates cookie changes made by responses to previously dispatched requests. In other words, succeeding requests reflect changes (additions and removals) made by any prior responses.

Cookie tracking requires synchronization between dispatches. As such, cookie tracking should not be enabled if a local client is being used to serve requests on multiple threads.

Errors

If launching the Rocket instance would fail, excepting network errors, the Error is returned.

use rocket::local::blocking::Client;

let rocket = rocket::build();
let client = Client::tracked(rocket);

pub fn untracked<P: Phase>(rocket: Rocket<P>) -> Result<Self, Error>[src]

Construct a new Client from an instance of Rocket without cookie tracking.

Cookie Tracking

Unlike the tracked() constructor, a Client returned from this method does not automatically propagate cookie changes and thus requires no synchronization between dispatches.

Errors

If launching the Rocket instance would fail, excepting network errors, the Error is returned.

use rocket::local::blocking::Client;

let rocket = rocket::build();
let client = Client::untracked(rocket);

pub fn new<P: Phase>(rocket: Rocket<P>) -> Result<Self, Error>[src]

👎 Deprecated since 0.5:

choose between Client::untracked() and Client::tracked()

Deprecated alias to Client::tracked().

pub fn rocket(&self) -> &Rocket<Orbit>[src]

Returns a reference to the Rocket this client is creating requests for.

Example

use rocket::local::blocking::Client;

let client: &Client = client;
let rocket = client.rocket();

pub fn cookies(&self) -> CookieJar<'_>[src]

Returns a cookie jar containing all of the cookies this client is currently tracking.

If cookie tracking is disabled, the returned jar will always be empty. Otherwise, it will contains all of the cookies collected from responses to requests dispatched by this client that have not expired.

Example

use rocket::local::blocking::Client;

let client: &Client = client;
let cookie = client.cookies();

pub fn get<'c, 'u: 'c, U>(&'c self, uri: U) -> LocalRequest<'c> where
    U: TryInto<Origin<'u>> + Display
[src]

Create a local GET request to the URI uri.

When dispatched, the request will be served by the instance of Rocket within self. The request is not dispatched automatically. To actually dispatch the request, call LocalRequest::dispatch() on the returned request.

Example

use rocket::local::blocking::Client;

let client: &Client = client;
let req = client.get("/hello");

pub fn put<'c, 'u: 'c, U>(&'c self, uri: U) -> LocalRequest<'c> where
    U: TryInto<Origin<'u>> + Display
[src]

Create a local PUT request to the URI uri.

When dispatched, the request will be served by the instance of Rocket within self. The request is not dispatched automatically. To actually dispatch the request, call LocalRequest::dispatch() on the returned request.

Example

use rocket::local::blocking::Client;

let client: &Client = client;
let req = client.put("/hello");

pub fn post<'c, 'u: 'c, U>(&'c self, uri: U) -> LocalRequest<'c> where
    U: TryInto<Origin<'u>> + Display
[src]

Create a local POST request to the URI uri.

When dispatched, the request will be served by the instance of Rocket within self. The request is not dispatched automatically. To actually dispatch the request, call LocalRequest::dispatch() on the returned request.

Example

use rocket::local::blocking::Client;

let client: &Client = client;
let req = client.post("/hello");

pub fn delete<'c, 'u: 'c, U>(&'c self, uri: U) -> LocalRequest<'c> where
    U: TryInto<Origin<'u>> + Display
[src]

Create a local DELETE request to the URI uri.

When dispatched, the request will be served by the instance of Rocket within self. The request is not dispatched automatically. To actually dispatch the request, call LocalRequest::dispatch() on the returned request.

Example

use rocket::local::blocking::Client;

let client: &Client = client;
let req = client.delete("/hello");

pub fn options<'c, 'u: 'c, U>(&'c self, uri: U) -> LocalRequest<'c> where
    U: TryInto<Origin<'u>> + Display
[src]

Create a local OPTIONS request to the URI uri.

When dispatched, the request will be served by the instance of Rocket within self. The request is not dispatched automatically. To actually dispatch the request, call LocalRequest::dispatch() on the returned request.

Example

use rocket::local::blocking::Client;

let client: &Client = client;
let req = client.options("/hello");

pub fn head<'c, 'u: 'c, U>(&'c self, uri: U) -> LocalRequest<'c> where
    U: TryInto<Origin<'u>> + Display
[src]

Create a local HEAD request to the URI uri.

When dispatched, the request will be served by the instance of Rocket within self. The request is not dispatched automatically. To actually dispatch the request, call LocalRequest::dispatch() on the returned request.

Example

use rocket::local::blocking::Client;

let client: &Client = client;
let req = client.head("/hello");

pub fn patch<'c, 'u: 'c, U>(&'c self, uri: U) -> LocalRequest<'c> where
    U: TryInto<Origin<'u>> + Display
[src]

Create a local PATCH request to the URI uri.

When dispatched, the request will be served by the instance of Rocket within self. The request is not dispatched automatically. To actually dispatch the request, call LocalRequest::dispatch() on the returned request.

Example

use rocket::local::blocking::Client;

let client: &Client = client;
let req = client.patch("/hello");

pub fn req<'c, 'u: 'c, U>(&'c self, method: Method, uri: U) -> LocalRequest<'c> where
    U: TryInto<Origin<'u>> + Display
[src]

Create a local GET request to the URI uri.

When dispatched, the request will be served by the instance of Rocket within self. The request is not dispatched automatically. To actually dispatch the request, call LocalRequest::dispatch() on the returned request.

Example

use rocket::local::blocking::Client;
use rocket::http::Method;

let client: &Client = client;
client.req(Method::Get, "/hello");

Trait Implementations

impl Debug for Client[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl Drop for Client[src]

fn drop(&mut self)[src]

Executes the destructor for this type. Read more

Auto Trait Implementations

impl !RefUnwindSafe for Client

impl Send for Client

impl !Sync for Client

impl Unpin for Client

impl !UnwindSafe for Client

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T> Instrument for T[src]

fn instrument(self, span: Span) -> Instrumented<Self>[src]

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

fn in_current_span(self) -> Instrumented<Self>[src]

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

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

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> IntoCollection<T> for T

pub fn into_collection<A>(self) -> SmallVec<A> where
    A: Array<Item = T>, 

Converts self into a collection.

pub fn mapped<U, F, A>(self, f: F) -> SmallVec<A> where
    F: FnMut(T) -> U,
    A: Array<Item = U>, 

impl<T> Same<T> for T

type Output = T

Should always be Self

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

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

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

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

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

pub fn vzip(self) -> V