github.com/TeaOSLab/EdgeNode@v1.3.8/internal/waf/checkpoints/request_headers_test.go (about)

     1  // Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
     2  
     3  package checkpoints
     4  
     5  import (
     6  	"net/http"
     7  	"runtime"
     8  	"sort"
     9  	"strings"
    10  	"testing"
    11  )
    12  
    13  func BenchmarkRequestHeadersCheckpoint_RequestValue(b *testing.B) {
    14  	runtime.GOMAXPROCS(1)
    15  
    16  	var header = http.Header{
    17  		"Content-Type":    []string{"keep-alive"},
    18  		"User-Agent":      []string{"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36"},
    19  		"Accept-Encoding": []string{"gzip, deflate, br"},
    20  		"Referer":         []string{"https://goedge.cn/"},
    21  	}
    22  
    23  	for i := 0; i < b.N; i++ {
    24  		var headers = []string{}
    25  		for k, v := range header {
    26  			for _, subV := range v {
    27  				headers = append(headers, k+": "+subV)
    28  			}
    29  		}
    30  		sort.Strings(headers)
    31  		_ = strings.Join(headers, "\n")
    32  	}
    33  }