#[non_exhaustive]pub enum Method {
Get,
Head,
Post,
Put,
Delete,
Connect,
Options,
Trace,
Patch,
Other,
}Expand description
The request method.
Methods are case-sensitive (RFC 9110 section 9.1): get is a different,
unregistered method and parses as Method::Other. The exact text is
always available from RequestHead::method_str.
A variant is added only when an RFC registers the method.
§Examples
use http_net::Method;
assert_eq!(Method::from_bytes(b"GET"), Method::Get);
assert_eq!(Method::from_bytes(b"get"), Method::Other);
assert_eq!(Method::Post.as_str(), Some("POST"));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Get
GET
Head
HEAD: the response carries headers but never a body.
Post
POST
Put
PUT
Delete
DELETE
Connect
CONNECT: the target is in authority form; a 2xx response turns the
connection into a tunnel.
Options
OPTIONS: the only method that may use the * target.
Trace
TRACE
Patch
PATCH
Other
Any other token.
Implementations§
Source§impl Method
impl Method
Sourcepub fn from_bytes(token: &[u8]) -> Self
pub fn from_bytes(token: &[u8]) -> Self
Classifies a method token (case-sensitive).
§Examples
assert_eq!(http_net::Method::from_bytes(b"PATCH"), http_net::Method::Patch);Sourcepub const fn as_str(&self) -> Option<&'static str>
pub const fn as_str(&self) -> Option<&'static str>
The method’s text, or None for Method::Other.
§Examples
assert_eq!(http_net::Method::Other.as_str(), None);Sourcepub const fn is_safe(&self) -> bool
pub const fn is_safe(&self) -> bool
Whether the method is safe (RFC 9110 section 9.2.1): GET, HEAD,
OPTIONS, TRACE. Method::Other is not; decide from the text.
§Examples
use http_net::Method;
assert!(Method::Head.is_safe());
assert!(!Method::Put.is_safe());Sourcepub const fn is_idempotent(&self) -> bool
pub const fn is_idempotent(&self) -> bool
Whether the method is idempotent (RFC 9110 section 9.2.2): the safe
methods plus PUT and DELETE.
§Examples
use http_net::Method;
assert!(Method::Delete.is_idempotent());
assert!(!Method::Post.is_idempotent());