pub struct Request {
pub method: String,
pub url: Url,
pub proto: String,
pub proto_major: u8,
pub proto_minor: u8,
pub header: Header,
pub body: Option<Body>,
pub content_length: i64,
pub transfer_encoding: Vec<String>,
pub host: String,
pub trailer: Header,
pub remote_addr: String,
/* private fields */
}Expand description
An HTTP request (incoming server-side or outgoing client-side).
Mirrors Go’s http.Request.
Fields§
§method: StringHTTP method (GET, POST, …).
url: UrlParsed request URL.
proto: StringProtocol version string, e.g. “HTTP/1.1”.
proto_major: u8§proto_minor: u8§header: HeaderRequest headers.
body: Option<Body>Request body; None after the body has been consumed or for bodyless methods.
content_length: i64-1 means unknown; ≥ 0 means exact byte count from Content-Length.
transfer_encoding: Vec<String>Transfer-Encoding values in order (e.g. [“chunked”]).
host: StringValue of the Host header (or from the URL for outgoing requests).
trailer: HeaderTrailing headers populated after a chunked body is fully read.
remote_addr: StringRemote address of the client (set by the server, empty on client requests).
Implementations§
Source§impl Request
impl Request
Sourcepub fn new(
method: &str,
url: &str,
body: Option<Body>,
) -> Result<Self, HttpError>
pub fn new( method: &str, url: &str, body: Option<Body>, ) -> Result<Self, HttpError>
Create a new outgoing request.
Port of Go’s http.NewRequest.
Sourcepub fn new_with_context(
method: &str,
url: &str,
body: Option<Body>,
ctx: Context,
) -> Result<Self, HttpError>
pub fn new_with_context( method: &str, url: &str, body: Option<Body>, ctx: Context, ) -> Result<Self, HttpError>
Create a new outgoing request tied to a context.
Port of Go’s http.NewRequestWithContext.
pub fn context(&self) -> &Context
Sourcepub fn with_context(self, ctx: Context) -> Self
pub fn with_context(self, ctx: Context) -> Self
Return a shallow clone of this request with the context replaced.
Port of Go’s (*Request).WithContext.
pub fn user_agent(&self) -> &str
pub fn referer(&self) -> &str
Sourcepub fn basic_auth(&self) -> Option<(String, String)>
pub fn basic_auth(&self) -> Option<(String, String)>
Parse and return Basic Auth credentials.
Port of Go’s (*Request).BasicAuth.
Return all cookies sent with the request.
Return the named cookie, or None.
Sourcepub fn parse_form(&mut self) -> Result<(), HttpError>
pub fn parse_form(&mut self) -> Result<(), HttpError>
Parse application/x-www-form-urlencoded body or query string.
Port of Go’s (*Request).ParseForm.
Sourcepub fn form_value(&self, key: &str) -> Option<&str>
pub fn form_value(&self, key: &str) -> Option<&str>
Return a form value by key (after calling parse_form).