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: u16HTTP Status code
headers: BTreeMap<String, String>Response headers
bytes: Vec<u8>Response body in bytes
url: StringThe final URL that was resolved
content_length: usizeThe byte length of the response
Implementations§
Source§impl HttpFetchResponse
impl HttpFetchResponse
Sourcepub fn is_ok(&self) -> bool
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());Sourcepub fn from_promise(promise_status: PromiseStatus) -> Self
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.
Sourcepub fn proxy_verification(
&self,
http_method: HttpFetchMethod,
request_body: Option<Vec<u8>>,
) -> Result<bool>
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
impl Clone for HttpFetchResponse
Source§fn clone(&self) -> HttpFetchResponse
fn clone(&self) -> HttpFetchResponse
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for HttpFetchResponse
impl Debug for HttpFetchResponse
Source§impl<'de> Deserialize<'de> for HttpFetchResponse
impl<'de> Deserialize<'de> for HttpFetchResponse
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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
impl FromBytes for HttpFetchResponse
Source§fn from_bytes(bytes: &[u8]) -> Result<Self>
fn from_bytes(bytes: &[u8]) -> Result<Self>
Source§impl Serialize for HttpFetchResponse
impl Serialize for HttpFetchResponse
Source§impl ToBytes for HttpFetchResponse
impl ToBytes for HttpFetchResponse
Auto Trait Implementations§
impl Freeze for HttpFetchResponse
impl RefUnwindSafe for HttpFetchResponse
impl Send for HttpFetchResponse
impl Sync for HttpFetchResponse
impl Unpin for HttpFetchResponse
impl UnwindSafe for HttpFetchResponse
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more