go-resty / resty

Simple HTTP and REST client library for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

setTimeout does not take effect

1n7erface opened this issue · comments

	client := resty.New()
	client.SetTimeout(3 * time.Second)
	client.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true})
	resp, _ := client.R().
		EnableTrace().
		SetHeader("Cookie", "rememberMe=agent").
		SetHeader("User-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36").
		SetHeader("Accept", "*/*").
		SetHeader("Accept-Language", "zh-CN,zh;q=0.9").
		SetHeader("Connection", "close").
		Get("http://43.136.81.55:9001")
	fmt.Println(resp.Request.TraceInfo())

When I use this code to request, the timeout here does not take effect because the protocol of the website is websocket.
image
When I used net/http to access, I found that the reason why the timeout did not take effect was when reading the response packet.
image
I think the ideal result should be to return status code and response headers and an empty response body.
Looking forward for your reply, thank you.

package main

import (
	"log"
	"github.com/gospider007/requests"
)

func main() {
	resp, err := requests.Get(nil, "http://43.136.81.55:9001/")
	if err != nil {
	    log.Panic(err)
	}
	log.Print(resp.StatusCode())
}