Skip to main content

HttpRequest

Struct HttpRequest 

Source
pub struct HttpRequest {
    pub method: String,
    pub url: String,
    pub headers: Vec<(String, String)>,
    pub body: Vec<u8>,
    pub timeout_ms: u32,
    pub max_response_bytes: u64,
    pub max_redirects: u32,
    pub allow_http: bool,
}
Expand description

Um pedido HTTP: o método, o endereço, os cabeçalhos e o corpo, com os limites que o provedor respeita (o prazo, o tamanho da resposta e os redirecionamentos).

Fields§

§method: String

GET, POST, PUT, PATCH, DELETE… (em maiúsculas).

§url: String§headers: Vec<(String, String)>§body: Vec<u8>§timeout_ms: u32

O prazo do pedido inteiro (conectar, mandar e ler), em milissegundos; 0: sem prazo.

§max_response_bytes: u64

A maior resposta aceita, em bytes (acima disso, erro); 0: o padrão (16 MB).

§max_redirects: u32

Quantos redirecionamentos seguir (0: nenhum; a resposta 3xx volta como está).

§allow_http: bool

Aceita http:// (sem TLS) para fora deste computador, também num redirecionamento. Desligado, só https://, e http:// só para localhost/127.0.0.1/::1.

Implementations§

Source§

impl HttpRequest

Source

pub fn new(method: &str, url: impl Into<String>) -> Self

Um pedido com o método e o endereço.

Source

pub fn get(url: impl Into<String>) -> Self

Source

pub fn post(url: impl Into<String>) -> Self

Source

pub fn put(url: impl Into<String>) -> Self

Source

pub fn patch(url: impl Into<String>) -> Self

Source

pub fn delete(url: impl Into<String>) -> Self

Source

pub fn header(self, name: &str, value: impl Into<String>) -> Self

Põe um cabeçalho (troca o de mesmo nome, sem diferença de maiúsculas).

Source

pub fn set_header(&mut self, name: &str, value: impl Into<String>)

Como header, sem consumir o pedido.

Source

pub fn header_value(&self, name: &str) -> Option<&str>

O valor de um cabeçalho do pedido.

Source

pub fn bearer(self, token: &str) -> Self

Authorization: Bearer <token>.

Source

pub fn body(self, body: impl Into<Vec<u8>>) -> Self

Source

pub fn json_text(self, json: impl Into<String>) -> Self

O corpo em texto JSON já montado, com Content-Type: application/json.

Source

pub fn timeout_ms(self, ms: u32) -> Self

Source

pub fn max_response_bytes(self, bytes: u64) -> Self

Source

pub fn max_redirects(self, n: u32) -> Self

Source

pub fn allow_http(self, allow: bool) -> Self

Source

pub fn response_limit(&self) -> u64

O limite da resposta valendo (0 vira o padrão).

Source

pub fn check_url(&self, url: &str) -> Result<(), String>

Confere o esquema de url (https, ou http como diz allow_http). Todo provedor chama antes de mandar e a cada redirecionamento.

Trait Implementations§

Source§

impl Clone for HttpRequest

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HttpRequest

Source§

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

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

impl Default for HttpRequest

Source§

fn default() -> Self

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

impl PartialEq for HttpRequest

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for HttpRequest

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.