Struct mio_httpc::CallBuilder

source ·
pub struct CallBuilder { /* private fields */ }
Expand description

Used to start a call and get a Call for it.

Implementations§

source§

impl CallBuilder

CallBuilder constructs a call. It is finished after calling: exec, simple_call, call or websocket.

Some headers are set automatically unless set explicitly: user-agent, connection, host, auth, content-length

If you’re only executing a one-off call you should set connection header to close as default is keep-alive.

If you do not set body, but do set content-length, it will wait for send body to be provided through Httpc::call_send. You must use a streaming interface in this case and can not use SimpleCall.

source

pub fn new() -> CallBuilder

source

pub fn get() -> CallBuilder

Start a GET request.

source

pub fn post(body: Vec<u8>) -> CallBuilder

Start a POST request.

source

pub fn put(body: Vec<u8>) -> CallBuilder

Start a PUT request.

source

pub fn delete() -> CallBuilder

Start a DELETE request.

source

pub fn options() -> CallBuilder

Start an OPTIONS request.

source

pub fn head() -> CallBuilder

Start a HEAD request.

source

pub fn method(&mut self, m: &str) -> &mut Self

Set method: “GET”, “POST”, “PUT”, “OPTIONS”, “DELETE” or “HEAD”

source

pub fn https(&mut self) -> &mut Self

Default: http

Use https for call. Shorthand for set_https(true)

source

pub fn set_https(&mut self, v: bool) -> &mut Self

Default: false

Use https for call.

source

pub fn host(&mut self, s: &str) -> &mut Self

Set host where to connect to. It can be a domain or IP address.

source

pub fn port(&mut self, p: u16) -> &mut Self

Set connection port.

source

pub fn event_token(&mut self, p: [usize; 2]) -> &mut Self

Specifically set mio token IDs for call. Must be outside of token range specified im Httpc::new Two tokens are required becase when initiating connection both ipv4 and ipv6 connections are attempted. First one to connect wins and the other one is closed.

source

pub fn auth(&mut self, us: &str, pw: &str) -> &mut Self

Use http authentication with username and password.

source

pub fn path(&mut self, inpath: &str) -> &mut Self

Set full path. No percent encoding is done. Will fail later if it contains invalid characters.

source

pub fn path_segm(&mut self, segm: &str) -> &mut Self

Add a single segment of path. Parts are delimited by / which are added automatically. Any path unsafe characters are percent encoded. If part contains /, it will be percent encoded!

source

pub fn path_segms(&mut self, parts: &[&str]) -> &mut Self

Add multiple segments in one go.

source

pub fn query(&mut self, k: &str, v: &str) -> &mut Self

Add a key-value pair to query. Any url unsafe characters are percent encoded.

source

pub fn query_list(&mut self, kvl: &[(&str, &str)]) -> &mut Self

Add multiple key-value pars in one go.

source

pub fn url(&mut self, url: &str) -> Result<&mut Self>

Set full URL. If not valid it will return error. Be mindful of characters that need to be percent encoded. Using https, path_segm, query and auth functions to construct URL is much safer as those encode data automatically.

source

pub fn body(&mut self, body: Vec<u8>) -> &mut Self

Set body.

source

pub fn header(&mut self, key: &str, value: &str) -> &mut CallBuilder

Set HTTP header.

source

pub fn exec(&mut self) -> Result<(Response, Vec<u8>)>

Execute directly. This will block until completion!

source

pub fn simple_call( &mut self, httpc: &mut Httpc, poll: &Registry ) -> Result<SimpleCall>

Consume and execute HTTP call. Returns SimpleCall interface. CallBuilder is invalid after this call and will panic if used again.

source

pub fn call(&mut self, httpc: &mut Httpc, poll: &Registry) -> Result<Call>

Consume and execute HTTP call. Return low level streaming call interface. CallBuilder is invalid after this call and will panic if used again.

source

pub fn websocket( &mut self, httpc: &mut Httpc, poll: &Registry ) -> Result<WebSocket>

Consume and start a WebSocket CallBuilder is invalid after this call and will panic if used again.

source

pub fn max_response(&mut self, m: usize) -> &mut Self

Default 10MB.

This will limit how big the internal Vec can grow. HTTP response headers are always stored in internal buffer. HTTP response body is stored in internal buffer if no external buffer is provided.

For WebSockets this will also be a received fragment size limit!

source

pub fn dns_retry_ms(&mut self, n: u64) -> &mut Self

Default: 100ms

Starting point of dns packet resends if nothing received. Every next resend timeout is 2x the previous one but stops at 1s. Make sure to call Httpc::timeout! So for 100ms: 100ms, 200ms, 400ms, 800ms, 1000ms, 1000ms…

source

pub fn chunked_parse(&mut self, b: bool) -> &mut Self

Default true.

Configurable because it entails copying the data stream.

source

pub fn chunked_max_chunk(&mut self, v: usize) -> &mut Self

Default 128K

Max size of chunk in a chunked transfer.

source

pub fn timeout_ms(&mut self, d: u64) -> &mut Self

Default 60s

Maximum amount of time a call should last. Make sure to call Httpc::timeout!

source

pub fn max_redirects(&mut self, v: u8) -> &mut Self

Default 4.

How many redirects to follow. 0 to disable following redirects.

source

pub fn gzip(&mut self, b: bool) -> &mut Self

Default true.

Sets Accept-Encoding: gzip, deflate Will decompress response.

source

pub fn insecure_do_not_verify_domain(&mut self) -> &mut Self

Default secure.

Turn off domain verification over ssl. This should only be used when testing as you are throwing away a big part of ssl security.

source

pub fn digest_auth(&mut self, v: bool) -> &mut Self

Use digest authentication. If you know server is using digest auth you REALLY should set it to true. If server is using basic authentication and you set digest_auth to true, mio_httpc will retry with basic. If not set, basic auth is assumed which is very insecure.

source

pub fn get_url(&mut self) -> String

Return constructed URL.

Trait Implementations§

source§

impl Debug for CallBuilder

source§

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

Formats the value using the given formatter. Read more
source§

impl Default for CallBuilder

source§

fn default() -> CallBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
§

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

§

fn vzip(self) -> V