func()

in pkg/hbone/hboned.go [131:177]


func (hac *HBoneAcceptedConn) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	t0 := time.Now()
	var proxyErr error
	defer func() {
		if r := recover(); r != nil {
			switch x := r.(type) {
			case error:
				proxyErr = x
			}
		}
		log.Println("hbone", "url", r.URL, "host", r.Host, "remote", r.RemoteAddr,
			"dur", time.Since(t0), "err", proxyErr)
	}()

	// TODO: parse Envoy / hbone headers.

	if strings.HasPrefix(r.RequestURI, "/_hbone/") {
		// Force the headers to be sent.
		w.(http.Flusher).Flush()
		portName := r.RequestURI[8:]
		switch portName {
		case "15003":
			// Default mTLS port.
			proxyErr = hac.hb.HandleTCPProxy(w, r.Body, "127.0.0.1:15003")
			return

		case "22":
			// TCP proxy for SSH ( no mTLS, SSH has its own equivalent)
			proxyErr = hac.hb.HandleTCPProxy(w, r.Body, "127.0.0.1:15022")
			return
		}

		val := hac.hb.Ports[portName]
		if val != "" {
			proxyErr = hac.hb.HandleTCPProxy(w, r.Body, val)
			return
		}
		w.WriteHeader(404)
		return
	}

	// This is not a tunnel, but regular request.

	// Make sure xfcc header is removed
	r.Header.Del("x-forwarded-client-cert")
	hac.hb.rp.ServeHTTP(w, r)
}