|
1 | 1 | use wasi::http::types::Method as WasiMethod;
|
2 | 2 |
|
3 |
| -/// The method for the HTTP request |
4 |
| -#[derive(Debug)] |
5 |
| -#[non_exhaustive] |
6 |
| -pub enum Method { |
7 |
| - /// The GET method requests transfer of a current selected representation |
8 |
| - /// for the target resource. |
9 |
| - Get, |
10 |
| - /// The HEAD method is identical to GET except that the server MUST NOT send a message body in |
11 |
| - /// the response. |
12 |
| - Head, |
13 |
| - /// The POST method requests that the target resource process the representation enclosed in |
14 |
| - /// the request according to the resource's own specific semantics. |
15 |
| - Post, |
16 |
| - /// The PUT method requests that the state of the target resource be created or replaced with |
17 |
| - /// the state defined by the representation enclosed in the request message payload. |
18 |
| - Put, |
19 |
| - /// The DELETE method requests that the origin server remove the association between the target |
20 |
| - /// resource and its current functionality. |
21 |
| - Delete, |
22 |
| - /// The CONNECT method requests that the recipient establish a tunnel to the destination origin |
23 |
| - /// server identified by the request-target and, if successful, thereafter restrict its |
24 |
| - /// behavior to blind forwarding of packets, in both directions, until the tunnel is closed. |
25 |
| - Connect, |
26 |
| - /// The OPTIONS method requests information about the communication options available for the |
27 |
| - /// target resource, at either the origin server or an intervening intermediary. |
28 |
| - Options, |
29 |
| - /// The TRACE method requests a remote, application-level loop-back of the request message. |
30 |
| - Trace, |
31 |
| - /// The PATCH method requests that a set of changes described in the request entity be applied |
32 |
| - /// to the resource identified by the Request- URI. |
33 |
| - /// |
34 |
| - Patch, |
35 |
| - /// Send a method not covered by this list. |
36 |
| - Other(String), |
37 |
| -} |
| 3 | +use super::Result; |
| 4 | +pub use http::Method; |
38 | 5 |
|
39 |
| -impl From<Method> for WasiMethod { |
40 |
| - fn from(value: Method) -> Self { |
41 |
| - match value { |
42 |
| - Method::Get => WasiMethod::Get, |
43 |
| - Method::Head => WasiMethod::Head, |
44 |
| - Method::Post => WasiMethod::Post, |
45 |
| - Method::Put => WasiMethod::Put, |
46 |
| - Method::Delete => WasiMethod::Delete, |
47 |
| - Method::Connect => WasiMethod::Connect, |
48 |
| - Method::Options => WasiMethod::Options, |
49 |
| - Method::Trace => WasiMethod::Trace, |
50 |
| - Method::Patch => WasiMethod::Patch, |
51 |
| - Method::Other(s) => WasiMethod::Other(s), |
52 |
| - } |
| 6 | +pub(crate) fn to_wasi_method(value: Method) -> WasiMethod { |
| 7 | + match value { |
| 8 | + Method::GET => WasiMethod::Get, |
| 9 | + Method::HEAD => WasiMethod::Head, |
| 10 | + Method::POST => WasiMethod::Post, |
| 11 | + Method::PUT => WasiMethod::Put, |
| 12 | + Method::DELETE => WasiMethod::Delete, |
| 13 | + Method::CONNECT => WasiMethod::Connect, |
| 14 | + Method::OPTIONS => WasiMethod::Options, |
| 15 | + Method::TRACE => WasiMethod::Trace, |
| 16 | + Method::PATCH => WasiMethod::Patch, |
| 17 | + other => WasiMethod::Other(other.as_str().to_owned()), |
53 | 18 | }
|
54 | 19 | }
|
55 | 20 |
|
56 |
| -impl From<WasiMethod> for Method { |
57 |
| - fn from(value: WasiMethod) -> Self { |
58 |
| - match value { |
59 |
| - WasiMethod::Get => Method::Get, |
60 |
| - WasiMethod::Head => Method::Head, |
61 |
| - WasiMethod::Post => Method::Post, |
62 |
| - WasiMethod::Put => Method::Put, |
63 |
| - WasiMethod::Delete => Method::Delete, |
64 |
| - WasiMethod::Connect => Method::Connect, |
65 |
| - WasiMethod::Options => Method::Options, |
66 |
| - WasiMethod::Trace => Method::Trace, |
67 |
| - WasiMethod::Patch => Method::Patch, |
68 |
| - WasiMethod::Other(s) => Method::Other(s), |
69 |
| - } |
70 |
| - } |
| 21 | +// This will become useful once we support IncomingRequest |
| 22 | +#[allow(dead_code)] |
| 23 | +pub(crate) fn from_wasi_method(value: WasiMethod) -> Result<Method> { |
| 24 | + Ok(match value { |
| 25 | + WasiMethod::Get => Method::GET, |
| 26 | + WasiMethod::Head => Method::HEAD, |
| 27 | + WasiMethod::Post => Method::POST, |
| 28 | + WasiMethod::Put => Method::PUT, |
| 29 | + WasiMethod::Delete => Method::DELETE, |
| 30 | + WasiMethod::Connect => Method::CONNECT, |
| 31 | + WasiMethod::Options => Method::OPTIONS, |
| 32 | + WasiMethod::Trace => Method::TRACE, |
| 33 | + WasiMethod::Patch => Method::PATCH, |
| 34 | + WasiMethod::Other(s) => Method::from_bytes(s.as_bytes())?, |
| 35 | + }) |
71 | 36 | }
|
0 commit comments