mirror of
https://github.com/TecharoHQ/anubis.git
synced 2026-04-11 02:58:49 +00:00
34 lines
625 B
Go
34 lines
625 B
Go
package entrypoint
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"net"
|
|
"net/http"
|
|
"net/http/httputil"
|
|
"net/url"
|
|
|
|
"golang.org/x/net/http2"
|
|
)
|
|
|
|
func newH2CReverseProxy(target *url.URL) *httputil.ReverseProxy {
|
|
director := func(req *http.Request) {
|
|
req.URL.Scheme = target.Scheme
|
|
req.URL.Host = target.Host
|
|
req.Host = target.Host
|
|
}
|
|
|
|
// Use h2c transport
|
|
transport := &http2.Transport{
|
|
AllowHTTP: true,
|
|
DialTLS: func(network, addr string, cfg *tls.Config) (net.Conn, error) {
|
|
// Just do plain TCP (h2c)
|
|
return net.Dial(network, addr)
|
|
},
|
|
}
|
|
|
|
return &httputil.ReverseProxy{
|
|
Director: director,
|
|
Transport: transport,
|
|
}
|
|
}
|