Closed NitinRamesh25 closed 10 months ago
This seems to work just fine, can you provide a complete sample where it doesn't work?
func main() {
go func() {
if err := http.ListenAndServe(":6060", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})); err != nil {
panic(err)
}
}()
// Give the server a second to start.
time.Sleep(time.Second)
req := &fasthttp.Request{}
req.SetRequestURI("http://localhost:6060")
req.Header.Add("Authorization", "...")
req.Header.SetMethod("HEAD")
req.SetHost("localhost:6060")
req.URI().SetScheme("http")
resp := &fasthttp.Response{}
fmt.Println("Sending request")
client := &fasthttp.Client{}
err := client.Do(req, resp)
if err != nil {
fmt.Println("Failed do: " + err.Error())
return
}
fmt.Println(resp)
}
Looks like my API proxy was sending chunked response. But the terminating chunk wasn't sent properly, thus leading to the client to wait forever.
Even though the chunk isn't terminated properly, I could get this to work for now by setting the two fields in the Response struct fasthttp.Response{SkipBody: true, StreamBody: true}
I noticed that a request with method
HEAD
successfully gets sent to the server, but the server response isn't returned by the fasthttp client. Hence theDo
method gets stuck, without giving the response.The same works fine with
net/http
package.Note:
GET
API for the same URL as theHEAD
, and that works fine with fasthttp client.The following are the sample code I used for testing.
fasthttp
net/http