MCPcopy Index your code
hub / github.com/php/frankenphp / ExampleServeHTTP

Function ExampleServeHTTP

frankenphp_test.go:806–833  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

804}
805
806func ExampleServeHTTP() {
807 if err := frankenphp.Init(); err != nil {
808 panic(err)
809 }
810 defer frankenphp.Shutdown()
811
812 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
813 // Drop headers whose name contains an underscore: CGI maps dashes to
814 // underscores, so "Foo_Bar" would be indistinguishable from "Foo-Bar"
815 // in $_SERVER and could spoof any header an app or proxy trusts.
816 // Whitelist any you genuinely need.
817 for name := range r.Header {
818 if strings.ContainsRune(name, '_') {
819 delete(r.Header, name)
820 }
821 }
822
823 req, err := frankenphp.NewRequestWithContext(r, frankenphp.WithRequestDocumentRoot("/path/to/document/root", false))
824 if err != nil {
825 panic(err)
826 }
827
828 if err := frankenphp.ServeHTTP(w, req); err != nil {
829 panic(err)
830 }
831 })
832 log.Fatal(http.ListenAndServe(":8080", nil))
833}
834
835func BenchmarkHelloWorld(b *testing.B) {
836 require.NoError(b, frankenphp.Init())

Callers

nothing calls this directly

Calls 5

InitFunction · 0.92
ShutdownFunction · 0.92
NewRequestWithContextFunction · 0.92
WithRequestDocumentRootFunction · 0.92
ServeHTTPFunction · 0.92

Tested by

no test coverage detected