Skip to content
Merged

Dev #50

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions httpclient/httpclient_methods.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
// httpclient_methods.go
package httpclient

/* Ref: https://www.rfc-editor.org/rfc/rfc7231#section-8.1.3

+---------+------+------------+
| Method | Safe | Idempotent |
+---------+------+------------+
| CONNECT | no | no |
| DELETE | no | yes |
| GET | yes | yes |
| HEAD | yes | yes |
| OPTIONS | yes | yes |
| POST | no | no |
| PUT | no | yes |
| TRACE | yes | yes |
+---------+------+------------+
*/

import "net/http"

// IsIdempotentHTTPMethod checks if the given HTTP method is idempotent.
func IsIdempotentHTTPMethod(method string) bool {
idempotentHTTPMethods := map[string]bool{
http.MethodGet: true,
http.MethodPut: true,
http.MethodDelete: true,
http.MethodGet: true,
http.MethodPut: true,
http.MethodDelete: true,
http.MethodHead: true,
http.MethodOptions: true,
http.MethodTrace: true,
}

return idempotentHTTPMethods[method]
Expand All @@ -17,8 +37,9 @@ func IsIdempotentHTTPMethod(method string) bool {
// PATCH can be idempotent but often isn't used as such.
func IsNonIdempotentHTTPMethod(method string) bool {
nonIdempotentHTTPMethods := map[string]bool{
http.MethodPost: true,
http.MethodPatch: true,
http.MethodPost: true,
http.MethodPatch: true,
http.MethodConnect: true,
}

return nonIdempotentHTTPMethods[method]
Expand Down
Loading