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

     1  package main
     2  
     3  import (
     4  	"log"
     5  	"net/textproto"
     6  	"slices"
     7  	"testing"
     8  
     9  	"github.com/gospider007/requests"
    10  )
    11  
    12  func TestOrderHeaders(t *testing.T) {
    13  
    14  	headers := requests.NewOrderMap()
    15  	headers.Set("Accept-Encoding", "gzip, deflate, br")
    16  	headers.Set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7")
    17  	headers.Set("User-Agent", requests.UserAgent)
    18  	headers.Set("Accept-Language", requests.AcceptLanguage)
    19  	headers.Set("Sec-Ch-Ua", requests.SecChUa)
    20  	headers.Set("Sec-Ch-Ua-Mobile", "?0")
    21  	headers.Set("Sec-Ch-Ua-Platform", `"Windows"`)
    22  	resp, err := requests.Get(nil, "https://tools.scrapfly.io/api/fp/anything", requests.RequestOption{
    23  		Headers: headers,
    24  		// ForceHttp1: true,
    25  	})
    26  	if err != nil {
    27  		t.Fatal(err)
    28  	}
    29  	jsonData, err := resp.Json()
    30  	header_order := jsonData.Find("ordered_headers_key")
    31  	if !header_order.Exists() {
    32  		t.Fatal("not found akamai")
    33  	}
    34  	i := -1
    35  	log.Print(header_order)
    36  	// log.Print(headers.Keys())
    37  	kks := []string{}
    38  	for _, kk := range headers.Keys() {
    39  		kks = append(kks, textproto.CanonicalMIMEHeaderKey(kk))
    40  	}
    41  	for _, key := range header_order.Array() {
    42  		kk := textproto.CanonicalMIMEHeaderKey(key.String())
    43  		if slices.Contains(kks, kk) {
    44  			i2 := slices.Index(kks, textproto.CanonicalMIMEHeaderKey(kk))
    45  			if i2 < i {
    46  				log.Print(header_order)
    47  				t.Fatal("not equal")
    48  			}
    49  			i = i2
    50  		}
    51  	}
    52  }