Add /request endpoint in test_server.bin
Add new endpoint in test_server application:
- /request prints the client request (method, URL, HTTP version and
headers) in the payload of the reply
/request can take a "response_code" parameter (ie,
"/request?response_code=404"), the server replies with the appropriate
HTTP response code to the client.
Change-Id: Ibc03f62da06a5bbb93959eac865e5f3f14caa50e
diff --git a/octavia_tempest_plugin/contrib/test_server/test_server.go b/octavia_tempest_plugin/contrib/test_server/test_server.go
index 27b6b2c..cb4089d 100644
--- a/octavia_tempest_plugin/contrib/test_server/test_server.go
+++ b/octavia_tempest_plugin/contrib/test_server/test_server.go
@@ -12,6 +12,7 @@
"net"
"net/http"
"os"
+ "strconv"
"sync"
"time"
)
@@ -69,6 +70,34 @@
io.WriteString(w, resp)
}
+func requestHandler(w http.ResponseWriter, r *http.Request) {
+ scoreboard.open()
+ defer scoreboard.close()
+
+ http.SetCookie(w, &sessCookie)
+
+ params := r.URL.Query()
+ if value, ok := params["response_code"]; ok {
+ if responseCode, err := strconv.Atoi(value[0]); err == nil {
+ w.WriteHeader(responseCode)
+ }
+ }
+
+ io.WriteString(w, fmt.Sprintf("%s %s %s\n",
+ r.Method, r.RequestURI, r.Proto))
+
+ io.WriteString(w, fmt.Sprintf("Host: %s\n", r.Host))
+
+ for key, values := range r.Header {
+ for _, value := range values {
+ header := fmt.Sprintf("%s: %s\n", key, value)
+ io.WriteString(w, header)
+ }
+ }
+ io.WriteString(w, "\n")
+ io.WriteString(w, resp)
+}
+
func slowHandler(w http.ResponseWriter, r *http.Request) {
scoreboard.open()
defer scoreboard.close()
@@ -113,6 +142,7 @@
http.HandleFunc("/slow", slowHandler)
http.HandleFunc("/stats", statsHandler)
http.HandleFunc("/reset", resetHandler)
+ http.HandleFunc("/request", requestHandler)
}
func httpServe(port int, id string) {
@@ -128,6 +158,7 @@
mux.Handle("/slow", httpsWrapper(slowHandler))
mux.Handle("/stats", httpsWrapper(statsHandler))
mux.Handle("/reset", httpsWrapper(resetHandler))
+ mux.Handle("/request", httpsWrapper(requestHandler))
var tlsConfig *tls.Config
if certpool != nil {