Skip to main content

HttpMethod

Enum HttpMethod 

Source
pub enum HttpMethod {
Show 13 variants Get, Post, Put, Patch, Delete, Head, Options, Trace, Connect, Other, All, Safe, Unsafe,
}
Expand description

HTTP 操作方法枚举。

ValueEnum 用于 clap 集成,使其可以在命令行参数中使用。

Variants§

§

Get

§

Post

§

Put

§

Patch

§

Delete

§

Head

§

Options

§

Trace

§

Connect

§

Other

代表非标准的 HTTP 方法。

§

All

代表所有 HTTP 方法,通常用于管理员权限。

§

Safe

代表所有安全的 HTTP 方法,你可以参看 HttpMethod::safe 获取 安全 一词的含义

§

Unsafe

代表所有不安全的 HTTP 方法,你可以参看 HttpMethod::safe 获取 安全 一词的含义

Implementations§

Source§

impl HttpMethod

Source

pub fn safe(self) -> bool

§判断一个方法是否安全

根据 MDN 以及 rfc7231 对于安全的定义

一个方法是否安全取决于该方法的请求在被服务器响应后,服务器的状态是否改变

或者说一个方法安不安全取决于是否蕴含着写入请求

所以,对于 OPTIONS 这类在通常认知中 会造成服务器信息暴露等问题的方法,仍然认为是安全的

  • 如果一个方法是只读的,如 HEADGET 等,那他就是安全的
  • 如果一个方法有写入的含义,如 PUTDELETE 等,那么就不安全

同时,在这里,由于有两个例外:HttpMethod::OtherHttpMethod::All 这两个标记

它们两个一个代表其他请求(rfc规范之外的),一个代表所有的请求,包括 rfc 规范之外的,所以都视为不安全

Source

pub fn as_str(self) -> &'static str

Trait Implementations§

Source§

impl Clone for HttpMethod

Source§

fn clone(&self) -> HttpMethod

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for HttpMethod

Source§

impl Debug for HttpMethod

Source§

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

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

impl<'de> Deserialize<'de> for HttpMethod

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 Eq for HttpMethod

Source§

impl From<&Method> for HttpMethod

Source§

fn from(value: &Method) -> Self

Converts to this type from the input type.
Source§

impl From<Method> for HttpMethod

Source§

fn from(value: Method) -> Self

Converts to this type from the input type.
Source§

impl Hash for HttpMethod

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for HttpMethod

Source§

fn eq(&self, other: &HttpMethod) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for HttpMethod

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 StructuralPartialEq for HttpMethod

Source§

impl ValueEnum for HttpMethod

Source§

fn value_variants<'a>() -> &'a [Self]

All possible argument values, in display order.
Source§

fn to_possible_value<'a>(&self) -> Option<PossibleValue>

The canonical argument value. Read more
Source§

fn from_str(input: &str, ignore_case: bool) -> Result<Self, String>

Parse an argument into Self.

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more