Skip to content

Commit

Permalink
test/http2: Add custom-response endpoint for flexible e2e testing
Browse files Browse the repository at this point in the history
Add a `/custom-response` endpoint that returns a configurable response
via the `CUSTOM_RESPONSE` environment variable. Enable flexible e2e
testing by allowing customised backend responses to simulate various
routing and behaviour scenarios without modifying the application or
rebuilding the container.
  • Loading branch information
frobware committed Nov 20, 2024
1 parent 6312671 commit 052f6b6
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/http2/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func lookupEnv(key, defaultVal string) string {
func Serve() {
crtFile := lookupEnv("TLS_CRT", defaultTLSCrt)
keyFile := lookupEnv("TLS_KEY", defaultTLSKey)
customResponse := lookupEnv("CUSTOM_RESPONSE", "custom response")

http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
fmt.Fprint(w, req.Proto)
Expand All @@ -33,6 +34,10 @@ func Serve() {
fmt.Fprint(w, "ready")
})

http.HandleFunc("/custom-response", func(w http.ResponseWriter, req *http.Request) {
fmt.Fprint(w, customResponse)
})

go func() {
port := lookupEnv("HTTP_PORT", defaultHTTPPort)
log.Printf("Listening on port %v\n", port)
Expand Down

0 comments on commit 052f6b6

Please sign in to comment.