github.com/gospider007/requests@v0.0.0-20240506025355-c73d46169a23/test/cookies/setCookies_test.go (about)

     1  package main
     2  
     3  import (
     4  	"context"
     5  	"log"
     6  	"net/http"
     7  	"testing"
     8  
     9  	"github.com/gospider007/requests"
    10  )
    11  
    12  func TestSetCookies(t *testing.T) {
    13  	session, _ := requests.NewClient(context.TODO())
    14  
    15  	_, err := session.Get(context.TODO(), "https://www.baidu.com")
    16  	if err != nil {
    17  		log.Panic(err)
    18  	}
    19  	_, err = session.Get(context.TODO(), "https://www.baidu.com", requests.RequestOption{
    20  		RequestCallBack: func(ctx context.Context, request *http.Request, response *http.Response) error {
    21  			if request.Cookies() == nil {
    22  				log.Panic("cookie is nil")
    23  			}
    24  			return nil
    25  		},
    26  	})
    27  	if err != nil {
    28  		log.Panic(err)
    29  	}
    30  }