Struct alipay_rs::Response

source ·
pub struct Response(_);

Implementations§

source§

impl Response

source

pub fn new(resp: UreqResponse) -> Self

source

pub fn get_url(&self) -> &str

The URL we ended up at. This can differ from the request url when we have followed redirects.

source

pub fn http_version(&self) -> &str

The http version: HTTP/1.1

source

pub fn status(&self) -> u16

The status as a u16: 200

source

pub fn status_text(&self) -> &str

The status text: OK

The HTTP spec allows for non-utf8 status texts. This uses from_utf8_lossy to convert such lines to &str.

source

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

The header value for the given name, or None if not found.

For historical reasons, the HTTP spec allows for header values to be encoded using encodings like iso-8859-1. Such encodings means the values are not possible to interpret as utf-8.

In case the header value can’t be read as utf-8, this function returns None (while the name is visible in Response::headers_names()).

source

pub fn headers_names(&self) -> Vec<String>

A list of the header names in this response. Lowercased to be uniform.

It’s possible for a header name to be returned by this function, and still give a None value. See Response::header() for an explanation as to why.

source

pub fn has(&self, name: &str) -> bool

Tells if the response has the named header.

source

pub fn all(&self, name: &str) -> Vec<&str>

All headers corresponding values for the give name, or empty vector.

source

pub fn content_type(&self) -> &str

The content type part of the “Content-Type” header without the charset.

source

pub fn charset(&self) -> &str

The character set part of the “Content-Type”.

source

pub fn into_reader(self) -> Box<dyn Read + Send + Sync + 'static>

Turn this response into a impl Read of the body.

  1. If Transfer-Encoding: chunked, the returned reader will unchunk it and any Content-Length header is ignored.
  2. If Content-Length is set, the returned reader is limited to this byte length regardless of how many bytes the server sends.
  3. If no length header, the reader is until server stream end.

Note: If you use read_to_end() on the resulting reader, a malicious server might return enough bytes to exhaust available memory. If you’re making requests to untrusted servers, you should use .take() to limit the response bytes read.

source

pub fn into_string(self) -> Result<String>

Turn this response into a String of the response body. By default uses utf-8, but can work with charset, see below.

This is potentially memory inefficient for large bodies since the implementation first reads the reader to end into a Vec<u8> and then attempts to decode it using the charset.

If the response is larger than 10 megabytes, this will return an error.

source

pub fn into_json<T: DeserializeOwned>(self) -> Result<T>

Read the body of this response into a serde_json::Value, or any other type that implements the serde::Deserialize trait.

You must use either a type annotation as shown below (message: Message), or the [turbofish operator] (::<Type>) so Rust knows what type you are trying to read.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

impl<T> Typeable for Twhere T: Any,

§

fn get_type(&self) -> TypeId

Get the TypeId of this object.
§

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

§

fn vzip(self) -> V

§

impl<T> UnsafeAny for Twhere T: Any,