1+ // httpclient_methods.go
12package httpclient
23
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+
320import "net/http"
421
522// IsIdempotentHTTPMethod checks if the given HTTP method is idempotent.
623func IsIdempotentHTTPMethod (method string ) bool {
724 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 ,
1131 }
1232
1333 return idempotentHTTPMethods [method ]
@@ -17,8 +37,9 @@ func IsIdempotentHTTPMethod(method string) bool {
1737// PATCH can be idempotent but often isn't used as such.
1838func IsNonIdempotentHTTPMethod (method string ) bool {
1939 nonIdempotentHTTPMethods := map [string ]bool {
20- http .MethodPost : true ,
21- http .MethodPatch : true ,
40+ http .MethodPost : true ,
41+ http .MethodPatch : true ,
42+ http .MethodConnect : true ,
2243 }
2344
2445 return nonIdempotentHTTPMethods [method ]
0 commit comments