1
+ // httpclient_methods.go
1
2
package httpclient
2
3
4
+ /* Ref: https://www.rfc-editor.org/rfc/rfc7231#section-8.1.3
5
+
6
+ +---------+------+------------+
7
+ | Method | Safe | Idempotent |
8
+ +---------+------+------------+
9
+ | CONNECT | no | no |
10
+ | DELETE | no | yes |
11
+ | GET | yes | yes |
12
+ | HEAD | yes | yes |
13
+ | OPTIONS | yes | yes |
14
+ | POST | no | no |
15
+ | PUT | no | yes |
16
+ | TRACE | yes | yes |
17
+ +---------+------+------------+
18
+ */
19
+
3
20
import "net/http"
4
21
5
22
// IsIdempotentHTTPMethod checks if the given HTTP method is idempotent.
6
23
func IsIdempotentHTTPMethod (method string ) bool {
7
24
idempotentHTTPMethods := map [string ]bool {
8
- http .MethodGet : true ,
9
- http .MethodPut : true ,
10
- http .MethodDelete : true ,
25
+ http .MethodGet : true ,
26
+ http .MethodPut : true ,
27
+ http .MethodDelete : true ,
28
+ http .MethodHead : true ,
29
+ http .MethodOptions : true ,
30
+ http .MethodTrace : true ,
11
31
}
12
32
13
33
return idempotentHTTPMethods [method ]
@@ -17,8 +37,9 @@ func IsIdempotentHTTPMethod(method string) bool {
17
37
// PATCH can be idempotent but often isn't used as such.
18
38
func IsNonIdempotentHTTPMethod (method string ) bool {
19
39
nonIdempotentHTTPMethods := map [string ]bool {
20
- http .MethodPost : true ,
21
- http .MethodPatch : true ,
40
+ http .MethodPost : true ,
41
+ http .MethodPatch : true ,
42
+ http .MethodConnect : true ,
22
43
}
23
44
24
45
return nonIdempotentHTTPMethods [method ]
0 commit comments