Closed dgrr closed 6 years ago
Can you explain what the bug is exactly?
package main
import (
"github.com/erikdubbelboer/fasthttp"
)
func main() {
c := &fasthttp.Client{}
req, res := fasthttp.AcquireRequest(), fasthttp.AcquireResponse()
req.Header.SetMethod("POST")
req.SetRequestURI("...")
args := req.PostArgs()
args.Add("some", "value")
c.Do(req, res)
}
This code makes POST request. I think that the error is that the PostArgs won't be used in POST request, because Do function does not consider postArgs var of Request structure. The correct way was the following:
package main
import (
"github.com/erikdubbelboer/fasthttp"
)
func main() {
c := &fasthttp.Client{}
req, res := fasthttp.AcquireRequest(), fasthttp.AcquireResponse()
req.Header.SetMethod("POST")
req.SetRequestURI("...")
args := req.PostArgs()
args.Add("some", "value")
req.SetBody(args.QueryString())
c.Do(req, res)
}
Ok seems like a good fix. Should I just merge that one commit or do you want to make a pull request for it (from a separate branch on your fork)?
If I want to modify the content in the body, I need to code as this?
req.SetBody([]byte("a=1")) // existing body
req.PostArgs().Add("b", "2") // add another value
req.SetBody(req.PostArgs().QueryString()) // reset the body
Do function does not consider Args of Request parameter.
I will try to fix it tomorrow.