go-resty / resty

Simple HTTP and REST client library for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

retrying of non-idempotent methods

F7502 opened this issue · comments

We realized that resty is retrying any HTTP method, even non-idempotent ones. However, this is very unexpected and conflicts with the HTTP specification:
https://datatracker.ietf.org/doc/html/rfc7231#section-4.2.2

In our case it was a POST request that was retried and this then caused problems in our system.

Ideally, resty should change its default behavior to comply with the HTTP specification and only retry idempotent methods.

For now, we managed to achieve the same using a custom retry condition:

AddRetryCondition(
	func(r *resty.Response, err error) bool {
		return isIdempotent(r.Request.Method)
	},
).

@F7502 Thanks for reporting it.
We can change Resty's default behavior in v3 and provide an on-demand option for Resty users to enable it for other methods.

Sounds good, many thanks for taking this up!