-
-
Save krancour/851ad4e3dbef0e09ebc1f92cc56e4c9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type HTTPReverseProxy interface { | |
Proxy(w http.ResponseWriter, r *http.Request) | |
} | |
type httpReverseProxy struct { | |
proxyHTTP2RequestFn func(http.ResponseWriter, *http.Request) | |
proxyHTTP1xRequestFn func(http.ResponseWriter, *http.Request) | |
} | |
func NewHTTPReverseProxy() HTTPReverseProxy { | |
return &httpReverseProxy{ | |
proxyHTTP2RequestFn: defaultProxyHTTP2Request, | |
proxyHTTP1xRequestFn: defaultProxyHTTP1xRequest, | |
} | |
} | |
func (h *httpReverseProxy) Proxy(w http.ResponseWriter, r *http.Request) { | |
if r.ProtoMajor == 2 { | |
h.proxyHTTP2RequestFn(w, r) | |
} else { | |
h.proxyHTTP1xRequestFn(w, r) | |
} | |
} | |
func defaultProxyHTTP2Request(w http.ResponseWriter, r *http.Request) { | |
// Handle HTTP/2 requests | |
// ... | |
} | |
func defaultProxyHTTP1xRequest(w http.ResponseWriter, r *http.Request) { | |
// Handle HTTP/1.x requests | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment