(b *testing.B)
| 985 | } |
| 986 | |
| 987 | func BenchmarkUncommonHeaders(b *testing.B) { |
| 988 | require.NoError(b, frankenphp.Init()) |
| 989 | b.Cleanup(frankenphp.Shutdown) |
| 990 | |
| 991 | cwd, _ := os.Getwd() |
| 992 | testDataDir := cwd + "/testdata/" |
| 993 | |
| 994 | // Mimics headers of a request sent by Firefox to GitHub |
| 995 | headers := http.Header{} |
| 996 | headers.Add(strings.Clone("Accept"), strings.Clone("text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8")) |
| 997 | headers.Add(strings.Clone("Accept-Encoding"), strings.Clone("gzip, deflate, br")) |
| 998 | headers.Add(strings.Clone("Accept-Language"), strings.Clone("fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3")) |
| 999 | headers.Add(strings.Clone("Cache-Control"), strings.Clone("no-cache")) |
| 1000 | headers.Add(strings.Clone("Connection"), strings.Clone("keep-alive")) |
| 1001 | headers.Add(strings.Clone("Cookie"), strings.Clone("user_session=myrandomuuid; __Host-user_session_same_site=myotherrandomuuid; dotcom_user=dunglas; logged_in=yes; _foo=barbarbarbarbarbar; _device_id=anotherrandomuuid; color_mode=foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar; preferred_color_mode=light; tz=Europe%2FParis; has_recent_activity=1")) |
| 1002 | headers.Add(strings.Clone("DNT"), strings.Clone("1")) |
| 1003 | headers.Add(strings.Clone("Host"), strings.Clone("example.com")) |
| 1004 | headers.Add(strings.Clone("Pragma"), strings.Clone("no-cache")) |
| 1005 | headers.Add(strings.Clone("Sec-Fetch-Dest"), strings.Clone("document")) |
| 1006 | headers.Add(strings.Clone("Sec-Fetch-Mode"), strings.Clone("navigate")) |
| 1007 | headers.Add(strings.Clone("Sec-Fetch-Site"), strings.Clone("cross-site")) |
| 1008 | headers.Add(strings.Clone("Sec-GPC"), strings.Clone("1")) |
| 1009 | headers.Add(strings.Clone("Upgrade-Insecure-Requests"), strings.Clone("1")) |
| 1010 | headers.Add(strings.Clone("User-Agent"), strings.Clone("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:122.0) Gecko/20100101 Firefox/122.0")) |
| 1011 | // Some uncommon headers |
| 1012 | headers.Add(strings.Clone("X-Super-Custom"), strings.Clone("Foo")) |
| 1013 | headers.Add(strings.Clone("Super-Super-Custom"), strings.Clone("Foo")) |
| 1014 | headers.Add(strings.Clone("Super-Super-Custom"), strings.Clone("Bar")) |
| 1015 | headers.Add(strings.Clone("Very-Custom"), strings.Clone("1")) |
| 1016 | |
| 1017 | opt := frankenphp.WithRequestDocumentRoot(testDataDir, false) |
| 1018 | handler := func(w http.ResponseWriter, r *http.Request) { |
| 1019 | req, err := frankenphp.NewRequestWithContext(r, opt) |
| 1020 | require.NoError(b, err) |
| 1021 | |
| 1022 | r.Header = headers |
| 1023 | |
| 1024 | require.NoError(b, frankenphp.ServeHTTP(w, req)) |
| 1025 | } |
| 1026 | |
| 1027 | req := httptest.NewRequest("GET", "http://example.com/server-variable.php", nil) |
| 1028 | w := httptest.NewRecorder() |
| 1029 | |
| 1030 | for b.Loop() { |
| 1031 | handler(w, req) |
| 1032 | } |
| 1033 | } |
| 1034 | |
| 1035 | func TestRejectInvalidHeaders_module(t *testing.T) { testRejectInvalidHeaders(t, &testOptions{}) } |
| 1036 | func TestRejectInvalidHeaders_worker(t *testing.T) { |
nothing calls this directly
no test coverage detected