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

     1  package requests
     2  
     3  import (
     4  	"net/http"
     5  )
     6  
     7  const (
     8  	chromeV        = "120"
     9  	chromeE        = ".0.6099.28"
    10  	UserAgent      = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/" + chromeV + ".0.0.0 Safari/537.36 Edg/" + chromeV + chromeE
    11  	SecChUa        = `"Chromium";v="` + chromeV + `", "Microsoft Edge";v="` + chromeV + `", "Not=A?Brand";v="99"`
    12  	AcceptLanguage = "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6"
    13  )
    14  
    15  func defaultHeaders() http.Header {
    16  	return http.Header{
    17  		"User-Agent":         []string{UserAgent},
    18  		"Accept":             []string{"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"},
    19  		"Accept-Encoding":    []string{"gzip, deflate, br"},
    20  		"Accept-Language":    []string{AcceptLanguage},
    21  		"Sec-Ch-Ua":          []string{SecChUa},
    22  		"Sec-Ch-Ua-Mobile":   []string{"?0"},
    23  		"Sec-Ch-Ua-Platform": []string{`"Windows"`},
    24  	}
    25  }
    26  
    27  func (obj *RequestOption) initHeaders() (http.Header, []string, error) {
    28  	if obj.Headers == nil {
    29  		return nil, nil, nil
    30  	}
    31  	switch headers := obj.Headers.(type) {
    32  	case http.Header:
    33  		return headers.Clone(), nil, nil
    34  	case *OrderMap:
    35  		head, order := headers.parseHeaders()
    36  		return head, order, nil
    37  	default:
    38  		_, dataMap, _, err := obj.newBody(headers, mapType)
    39  		if err != nil {
    40  			return nil, nil, err
    41  		}
    42  		if dataMap == nil {
    43  			return nil, nil, nil
    44  		}
    45  		head, _ := dataMap.parseHeaders()
    46  		return head, nil, err
    47  	}
    48  }