go-resty / resty

Simple HTTP and REST client library for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OnBeforeRequest and default middleware order documentation and code mismatch

leejuyuu opened this issue · comments

The documentation of OnBeforeRequest

resty/client.go

Lines 403 to 405 in 3d08b36

// OnBeforeRequest method appends request middleware into the before request chain.
// Its gets applied after default Resty request middlewares and before request
// been sent from Resty to host server.

says that the middleware set by this function is applied after the default middlewares.

However, when the request is executed, the order is reversed.

resty/client.go

Lines 896 to 912 in 3d08b36

// Apply Request middleware
var err error
// user defined on before request methods
// to modify the *resty.Request object
for _, f := range c.udBeforeRequest {
if err = f(c, req); err != nil {
return nil, wrapNoRetryErr(err)
}
}
// resty middlewares
for _, f := range c.beforeRequest {
if err = f(c, req); err != nil {
return nil, wrapNoRetryErr(err)
}
}

I think this resulted in #517.

I am not sure which side is the intended result.

@leejuyuu Thanks for bringing it up. I didn't notice it. The documentation needs correction. I will correct it, or you could submit the PR. Please let me know.

As @0140454 mentioned in the #517 (comment), this is the correct order of execution.

@jeevatkm Thanks for the reply! Opened #701.