in integration-test/webserver/main.go [178:221]
func main() {
args := flag.String("args", "", `Example usage: '2h-valid' to send StatusCode: 200, ResponseBody: { "ApplicationHealthState": "Healthy", "CustomMetrics": "<valid json>"}`)
securityProtocol := flag.String("securityProtocol", "tls1.3", "Specifies the security protocol to use for the HTTPS server. Valid options are: tls1.0, tls1.1, tls1.2, tls1.3, ssl3.0. Default is tls1.3.")
flag.Parse()
originalArgs := strings.Split(*args, ",")
arguments := strings.Split(*args, ",")
var shouldExitOnEmptyArgs = len(arguments) > 0
httpMutex := http.NewServeMux()
httpServer := http.Server{
Addr: ":8080",
Handler: httpMutex}
httpsServer := http.Server{
Addr: ":4430", //changing default port from 443 to 4430 to avoid conflict with other services
Handler: httpMutex,
TLSConfig: &tls.Config{
MinVersion: getSecurityProtocolVersion(*securityProtocol),
MaxVersion: getSecurityProtocolVersion(*securityProtocol)},
}
// sends json resonse body with application health state expected by extension
// looks at the first state in the healthStates array and dequeues that element after its iterated
httpMutex.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
healthHandler(w, r, &arguments)
// if arguments is non-empty, this means that the test is only meant to run till we iterate over all arguments, so the servers are shutdown
if shouldExitOnEmptyArgs && len(arguments) == 0 {
go func() {
log.Printf("Finished serving arguments: %v", originalArgs)
log.Printf("Shutting down http and https server")
httpServer.Shutdown(context.Background())
httpsServer.Shutdown(context.Background())
}()
}
})
log.Printf("Arguments: %v, len: %v", arguments, len(arguments))
log.Printf("Starting http server...")
go httpServer.ListenAndServe()
log.Printf("Starting https server...")
log.Fatal(httpsServer.ListenAndServeTLS("webservercert.pem", "webserverkey.pem"))
log.Printf("Servers stopped...")
}