@@ -782,8 +782,9 @@ func BenchmarkHelloWorld(b *testing.B) {
782782 cwd , _ := os .Getwd ()
783783 testDataDir := cwd + "/testdata/"
784784
785+ opt := frankenphp .WithRequestDocumentRoot (testDataDir , false )
785786 handler := func (w http.ResponseWriter , r * http.Request ) {
786- req , err := frankenphp .NewRequestWithContext (r , frankenphp . WithRequestDocumentRoot ( testDataDir , false ) )
787+ req , err := frankenphp .NewRequestWithContext (r , opt )
787788 require .NoError (b , err )
788789
789790 require .NoError (b , frankenphp .ServeHTTP (w , req ))
@@ -804,8 +805,9 @@ func BenchmarkEcho(b *testing.B) {
804805 cwd , _ := os .Getwd ()
805806 testDataDir := cwd + "/testdata/"
806807
808+ opt := frankenphp .WithRequestDocumentRoot (testDataDir , false )
807809 handler := func (w http.ResponseWriter , r * http.Request ) {
808- req , err := frankenphp .NewRequestWithContext (r , frankenphp . WithRequestDocumentRoot ( testDataDir , false ) )
810+ req , err := frankenphp .NewRequestWithContext (r , opt )
809811 require .NoError (b , err )
810812
811813 require .NoError (b , frankenphp .ServeHTTP (w , req ))
@@ -907,8 +909,57 @@ func BenchmarkServerSuperGlobal(b *testing.B) {
907909
908910 preparedEnv := frankenphp .PrepareEnv (env )
909911
912+ opts := []frankenphp.RequestOption {frankenphp .WithRequestDocumentRoot (testDataDir , false ), frankenphp .WithRequestPreparedEnv (preparedEnv )}
910913 handler := func (w http.ResponseWriter , r * http.Request ) {
911- req , err := frankenphp .NewRequestWithContext (r , frankenphp .WithRequestDocumentRoot (testDataDir , false ), frankenphp .WithRequestPreparedEnv (preparedEnv ))
914+ req , err := frankenphp .NewRequestWithContext (r , opts ... )
915+ require .NoError (b , err )
916+
917+ r .Header = headers
918+
919+ require .NoError (b , frankenphp .ServeHTTP (w , req ))
920+ }
921+
922+ req := httptest .NewRequest ("GET" , "http://example.com/server-variable.php" , nil )
923+ w := httptest .NewRecorder ()
924+
925+ for b .Loop () {
926+ handler (w , req )
927+ }
928+ }
929+
930+ func BenchmarkUncommonHeaders (b * testing.B ) {
931+ require .NoError (b , frankenphp .Init ())
932+ b .Cleanup (frankenphp .Shutdown )
933+
934+ cwd , _ := os .Getwd ()
935+ testDataDir := cwd + "/testdata/"
936+
937+ // Mimics headers of a request sent by Firefox to GitHub
938+ headers := http.Header {}
939+ headers .Add (strings .Clone ("Accept" ), strings .Clone ("text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8" ))
940+ headers .Add (strings .Clone ("Accept-Encoding" ), strings .Clone ("gzip, deflate, br" ))
941+ headers .Add (strings .Clone ("Accept-Language" ), strings .Clone ("fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3" ))
942+ headers .Add (strings .Clone ("Cache-Control" ), strings .Clone ("no-cache" ))
943+ headers .Add (strings .Clone ("Connection" ), strings .Clone ("keep-alive" ))
944+ 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" ))
945+ headers .Add (strings .Clone ("DNT" ), strings .Clone ("1" ))
946+ headers .Add (strings .Clone ("Host" ), strings .Clone ("example.com" ))
947+ headers .Add (strings .Clone ("Pragma" ), strings .Clone ("no-cache" ))
948+ headers .Add (strings .Clone ("Sec-Fetch-Dest" ), strings .Clone ("document" ))
949+ headers .Add (strings .Clone ("Sec-Fetch-Mode" ), strings .Clone ("navigate" ))
950+ headers .Add (strings .Clone ("Sec-Fetch-Site" ), strings .Clone ("cross-site" ))
951+ headers .Add (strings .Clone ("Sec-GPC" ), strings .Clone ("1" ))
952+ headers .Add (strings .Clone ("Upgrade-Insecure-Requests" ), strings .Clone ("1" ))
953+ 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" ))
954+ // Some uncommon headers
955+ headers .Add (strings .Clone ("X-Super-Custom" ), strings .Clone ("Foo" ))
956+ headers .Add (strings .Clone ("Super-Super-Custom" ), strings .Clone ("Foo" ))
957+ headers .Add (strings .Clone ("Super-Super-Custom" ), strings .Clone ("Bar" ))
958+ headers .Add (strings .Clone ("Very-Custom" ), strings .Clone ("1" ))
959+
960+ opt := frankenphp .WithRequestDocumentRoot (testDataDir , false )
961+ handler := func (w http.ResponseWriter , r * http.Request ) {
962+ req , err := frankenphp .NewRequestWithContext (r , opt )
912963 require .NoError (b , err )
913964
914965 r .Header = headers
0 commit comments