Files
requests/test/session_test.go
gospider c83d1aa4c2 sync
2025-07-24 16:50:47 +08:00

69 lines
1.5 KiB
Go

package main
import (
"log"
"testing"
"github.com/gospider007/requests"
)
func TestSession(t *testing.T) {
session, _ := requests.NewClient(nil)
for i := 0; i < 2; i++ {
resp, err := session.Get(nil, "https://www.baidu.com")
if err != nil {
t.Error(err)
}
log.Print(resp.Proto(), resp.IsNewConn())
resp.CloseBody(nil)
if i == 0 {
if !resp.IsNewConn() { //return is NewConn
t.Error("new conn error: ", i)
}
} else {
if resp.IsNewConn() {
t.Error("new conn error: ", i)
}
}
}
}
func TestSession2(t *testing.T) {
session, _ := requests.NewClient(nil)
for i := 0; i < 2; i++ {
resp, err := session.Get(nil, "https://httpbin.org/anything")
if err != nil {
t.Error(err)
}
log.Print(resp.Proto(), resp.IsNewConn())
if i == 0 {
if !resp.IsNewConn() { //return is NewConn
t.Error("new conn error: ", i)
}
} else {
if resp.IsNewConn() {
t.Error("new conn error: ", i)
}
}
}
}
func TestSession3(t *testing.T) {
session, _ := requests.NewClient(nil)
for i := 0; i < 2; i++ {
resp, err := session.Get(nil, "https://cloudflare-quic.com/", requests.RequestOption{ClientOption: requests.ClientOption{ForceHttp3: true}})
if err != nil {
t.Error(err)
}
log.Print(resp.Proto(), resp.IsNewConn())
if i == 0 {
if !resp.IsNewConn() { //return is NewConn
t.Error("new conn error: ", i)
}
} else {
if resp.IsNewConn() {
t.Error("new conn error: ", i)
}
}
}
}