pub struct HttpRequest {
pub method: String,
pub url: String,
pub headers: Vec<(String, String)>,
pub body: ByteBuf,
}Expand description
Represents an HTTP request.
This struct is used to encapsulate the details of an HTTP request, including the HTTP method, URL, headers, and body.
Fields§
§method: StringThe HTTP method (e.g., “GET”, “POST”).
url: StringThe URL of the request.
headers: Vec<(String, String)>A list of headers, where each header is represented as a key-value pair.
body: ByteBufThe body of the request, represented as a byte buffer.
Implementations§
Source§impl HttpRequest
impl HttpRequest
Sourcepub fn path(&self) -> &str
pub fn path(&self) -> &str
Extracts the path from the URL.
If the URL contains a query string, the path is the portion before the ?.
If no query string is present, the entire URL is returned.
§Examples
use ic_http_types::{HttpRequest};
use serde_bytes::ByteBuf;
let request = HttpRequest {
method: "GET".to_string(),
url: "/path/to/resource?query=1".to_string(),
headers: vec![],
body: ByteBuf::default(),
};
assert_eq!(request.path(), "/path/to/resource");Sourcepub fn raw_query_param(&self, param: &str) -> Option<&str>
pub fn raw_query_param(&self, param: &str) -> Option<&str>
Searches for the first appearance of a parameter in the request URL.
Returns None if the given parameter does not appear in the query string.
§Parameters
param: The name of the query parameter to search for.
§Examples
use ic_http_types::{HttpRequest};
use serde_bytes::ByteBuf;
let request = HttpRequest {
method: "GET".to_string(),
url: "/path?key=value".to_string(),
headers: vec![],
body: ByteBuf::default(),
};
assert_eq!(request.raw_query_param("key"), Some("value"));Trait Implementations§
Source§impl CandidType for HttpRequest
impl CandidType for HttpRequest
Source§impl Clone for HttpRequest
impl Clone for HttpRequest
Source§fn clone(&self) -> HttpRequest
fn clone(&self) -> HttpRequest
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 HttpRequest
impl Debug for HttpRequest
Source§impl<'de> Deserialize<'de> for HttpRequest
impl<'de> Deserialize<'de> for HttpRequest
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
Auto Trait Implementations§
impl Freeze for HttpRequest
impl RefUnwindSafe for HttpRequest
impl Send for HttpRequest
impl Sync for HttpRequest
impl Unpin for HttpRequest
impl UnwindSafe for HttpRequest
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