mirror of
https://github.com/gospider007/requests.git
synced 2025-12-24 13:57:52 +08:00
69 lines
1.5 KiB
Go
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)
|
|
}
|
|
}
|
|
}
|
|
}
|