HttpFetchResponse

Struct HttpFetchResponse 

Source
pub struct HttpFetchResponse {
    pub status: u16,
    pub headers: BTreeMap<String, String>,
    pub bytes: Vec<u8>,
    pub url: String,
    pub content_length: usize,
}
Expand description

Represents the response from an HTTP fetch request. This struct is serialized and the result is returned to the caller.

Fields§

§status: u16

HTTP Status code

§headers: BTreeMap<String, String>

Response headers

§bytes: Vec<u8>

Response body in bytes

§url: String

The final URL that was resolved

§content_length: usize

The byte length of the response

Implementations§

Source§

impl HttpFetchResponse

Source

pub fn is_ok(&self) -> bool

Returns true if the status code is in the 2xx range.

§Examples
use seda_sdk_rs::http::HttpFetchResponse;
let response = HttpFetchResponse {
    status: 200,
    headers: Default::default(),
    bytes: Vec::new(),
    url: "https://api.example.com/data".to_string(),
    content_length: 0,
};
assert!(response.is_ok());
Source

pub fn from_promise(promise_status: PromiseStatus) -> Self

Converts a PromiseStatus into an HttpFetchResponse, treating rejections as errors.

§Errors

Fails if the PromiseStatus is not a Fulfilled variant or if the deserialization fails.

Source

pub fn proxy_verification( &self, http_method: HttpFetchMethod, request_body: Option<Vec<u8>>, ) -> Result<bool>

Returns true if the proxy verification is successful. This is only meant to be called on the response to a proxy request and not a normal HTTP request.

§Examples
use std::collections::BTreeMap;
use seda_sdk_rs::http::{HttpFetchResponse, HttpFetchMethod};
let response = HttpFetchResponse {
    status: 200,
    headers: BTreeMap::from([("x-seda-signature", "signature"), ("x-seda-publickey", "publickey")]),
    bytes: Vec::new(),
    url: "https://api.example.com/data".to_string(),
    content_length: 10,
};
response.proxy_verification(HttpFetchMethod::Get, None);
§Errors

Fails if the x-seda-signature or x-seda-publickey headers are missing or invalid.

Trait Implementations§

Source§

impl Clone for HttpFetchResponse

Source§

fn clone(&self) -> HttpFetchResponse

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for HttpFetchResponse

Source§

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

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

impl<'de> Deserialize<'de> for HttpFetchResponse

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl FromBytes for HttpFetchResponse

Source§

fn from_bytes(bytes: &[u8]) -> Result<Self>

A way to convert the Bytes into the implementing type without consuming the original bytes. Read more
Source§

fn from_bytes_vec(bytes: Vec<u8>) -> Result<Self>

A way to convert the Bytes into the implementing type and consume the original bytes. Read more
Source§

impl Serialize for HttpFetchResponse

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl ToBytes for HttpFetchResponse

Source§

fn to_bytes(self) -> Bytes

Converts the implementing type to a Bytes instance. Read more
Source§

impl TryFrom<Vec<u8>> for HttpFetchResponse

Source§

type Error = Error

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

fn try_from(value: Vec<u8>) -> Result<Self, Self::Error>

Performs the conversion.

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 = 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>,

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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,