mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-02 11:56:02 +02:00
* integration-tests: switch to go for backends to support TLS scenarios * fix apply order * fix duplicate port value
69 lines
1.6 KiB
Go
69 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"flag"
|
|
"fmt"
|
|
"net/http"
|
|
"os"
|
|
)
|
|
|
|
func main() {
|
|
var (
|
|
certFile, keyFile, bindAddr string
|
|
)
|
|
|
|
flag.StringVar(&certFile, "cert-file", "", "the tls cert file to use")
|
|
flag.StringVar(&keyFile, "key-file", "", "the tls key file to use")
|
|
flag.StringVar(&bindAddr, "bind-addr", "", "the address to listen on")
|
|
flag.Parse()
|
|
|
|
var err error
|
|
if certFile != "" && keyFile != "" {
|
|
if bindAddr == "" {
|
|
bindAddr = ":5443"
|
|
}
|
|
fmt.Println("starting server on", bindAddr)
|
|
err = http.ListenAndServeTLS(bindAddr, certFile, keyFile, http.HandlerFunc(handle))
|
|
} else {
|
|
if bindAddr == "" {
|
|
bindAddr = ":5080"
|
|
}
|
|
fmt.Println("starting server on", bindAddr)
|
|
err = http.ListenAndServe(bindAddr, http.HandlerFunc(handle))
|
|
}
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "failed to listen and serve: %v", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
type Result struct {
|
|
Headers map[string]string `json:"headers"`
|
|
Method string `json:"method"`
|
|
Host string `json:"host"`
|
|
Port string `json:"port"`
|
|
Path string `json:"path"`
|
|
Query string `json:"query"`
|
|
RequestURI string `json:"requestURI"`
|
|
}
|
|
|
|
func handle(w http.ResponseWriter, r *http.Request) {
|
|
res := &Result{
|
|
Headers: map[string]string{},
|
|
Method: r.Method,
|
|
Host: r.Host,
|
|
Port: r.URL.Port(),
|
|
Path: r.URL.Path,
|
|
Query: r.URL.RawQuery,
|
|
RequestURI: r.RequestURI,
|
|
}
|
|
for k := range r.Header {
|
|
res.Headers[k] = r.Header.Get(k)
|
|
}
|
|
res.Headers["Host"] = r.Host
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(200)
|
|
_ = json.NewEncoder(w).Encode(res)
|
|
}
|