hedgedhttp icon indicating copy to clipboard operation
hedgedhttp copied to clipboard

Only hedge idempotent requests

Open MichaHoffmann opened this issue 1 year ago • 2 comments
trafficstars

I might be wrong, but I think right now we hedge all requests, regardless if idempotent or not which might result in a bug. Shouldnt we check that we only hedge idempotent requests to be safe?

MichaHoffmann avatar Aug 28 '24 12:08 MichaHoffmann

Maybe https://github.com/cristalhq/hedgedhttp/blob/main/hedged.go#L40-L41 *http.Request could be exposed to NextFn and then Next could return 0 when req.Method == "POST" (etc.)?

GiedriusS avatar Aug 28 '24 12:08 GiedriusS

Hey @MichaHoffmann you are right, cristalhq/hedgedhttp doesn't separate idempotent and non-idempotent requests. And will not 'cause idempotency can be achieved in a different way (header, cookie, url param, etc). Better to leave this responsibility to the user.

Regarding how this can be achived, @GiedriusS is absolutely correct. NextFn 1st return param says how many hedged request should be done, zero is exactly what is should be used for non-idempotent requests.

I will add GUIDE.md file and will document that (I'm shocked that there is no GUIDE.md, almost all other cristalhq libs have it).

cristaloleg avatar Aug 29 '24 10:08 cristaloleg