Skip to content

Commit 9a4108a

Browse files
authored
Merge pull request #50 from deploymenttheory/dev
Dev
2 parents c255a71 + c87811a commit 9a4108a

File tree

2 files changed

+153
-298
lines changed

2 files changed

+153
-298
lines changed

httpclient/httpclient_methods.go

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
1+
// httpclient_methods.go
12
package 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+
320
import "net/http"
421

522
// IsIdempotentHTTPMethod checks if the given HTTP method is idempotent.
623
func 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.
1838
func 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

Comments
 (0)