File
Blob: gateway/cgi.go
| 1 | package gateway |
| 2 | |
| 3 | import ( |
| 4 | "crypto/tls" |
| 5 | "fmt" |
| 6 | "net/http" |
| 7 | |
| 8 | "github.com/go-chi/chi/v5" |
| 9 | ) |
| 10 | |
| 11 | func (g *Gateway) mountCgiHandler(r *chi.Mux) { |
| 12 | r.Route("/specter-cgi", func(router chi.Router) { |
| 13 | router.Use(func(h http.Handler) http.Handler { |
| 14 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 15 | g.appendHeaders(r.ProtoAtLeast(3, 0))(w.Header()) |
| 16 | h.ServeHTTP(w, r) |
| 17 | }) |
| 18 | }) |
| 19 | |
| 20 | router.HandleFunc("/info", func(w http.ResponseWriter, r *http.Request) { |
| 21 | fmt.Fprintf(w, "specter.identity=%s\n", g.TunnelServer.Identity().GetAddress()) |
| 22 | fmt.Fprintf(w, "specter.peer=%s\n", r.RemoteAddr) |
| 23 | fmt.Fprintf(w, "tls.cipher=%s\n", tls.CipherSuiteName(r.TLS.CipherSuite)) |
| 24 | fmt.Fprintf(w, "tls.sni=%s\n", r.TLS.ServerName) |
| 25 | fmt.Fprintf(w, "http.host=%s\n", r.Host) |
| 26 | fmt.Fprintf(w, "http.proto=%s\n", r.Proto) |
| 27 | }) |
| 28 | |
| 29 | router.HandleFunc("/*", func(w http.ResponseWriter, r *http.Request) { |
| 30 | w.WriteHeader(http.StatusNoContent) |
| 31 | }) |
| 32 | }) |
| 33 | } |