Skip to content

Commit

Permalink
feat: enable --https flag for HTTPS servers
Browse files Browse the repository at this point in the history
  • Loading branch information
Morishiri committed Jan 7, 2021
1 parent 9c7aedc commit 5516660
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cmd/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ To expose port running on some local host e.g. 192.168.1.20 use 'loophole http <

func init() {
initServeCommand(httpCmd)
localEndpointSpecs.HTTPS = false
httpCmd.Flags().BoolVar(&displayOptions.DisableProxyErrorPage, "disable-proxy-error-page", false, "disable proxy error page and return 502 when backend is not available")
httpCmd.Flags().BoolVar(&localEndpointSpecs.HTTPS, "https", false, "use if your server is already using HTTPS")
httpCmd.Flags().BoolVar(&displayOptions.DisableProxyErrorPage, "disable-proxy-error-page", false, "disable proxy error page and return 502 when your server is not available")

rootCmd.AddCommand(httpCmd)
}
4 changes: 4 additions & 0 deletions internal/app/loophole/loophole.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ func createTLSReverseProxy(localEndpoint lm.Endpoint, siteID string, basicAuthUs
serverBuilder = serverBuilder.
DisableProxyErrorPage()
}
if localEndpoint.Protocol == "https" {
serverBuilder = serverBuilder.
EnableInsecureHTTPSBackend()
}

if el := log.Debug(); el.Enabled() {
el.
Expand Down
13 changes: 13 additions & 0 deletions internal/pkg/httpserver/httpserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type ProxyServerBuilder interface {
ToEndpoint(lm.Endpoint) ProxyServerBuilder
WithBasicAuth(string, string) ProxyServerBuilder
DisableProxyErrorPage() ProxyServerBuilder
EnableInsecureHTTPSBackend() ProxyServerBuilder
Build() (*http.Server, error)
}
type proxyServerBuilder struct {
Expand All @@ -67,6 +68,7 @@ type proxyServerBuilder struct {
basicAuthUsername string
basicAuthPassword string
disableProxyErrorPage bool
disableCertCheck bool
}

func (psb *proxyServerBuilder) ToEndpoint(endpoint lm.Endpoint) ProxyServerBuilder {
Expand All @@ -86,6 +88,11 @@ func (psb *proxyServerBuilder) DisableProxyErrorPage() ProxyServerBuilder {
return psb
}

func (psb *proxyServerBuilder) EnableInsecureHTTPSBackend() ProxyServerBuilder {
psb.disableCertCheck = true
return psb
}

func (psb *proxyServerBuilder) Build() (*http.Server, error) {
proxy := httputil.NewSingleHostReverseProxy(&url.URL{
Scheme: psb.endpoint.Protocol,
Expand All @@ -95,6 +102,12 @@ func (psb *proxyServerBuilder) Build() (*http.Server, error) {
proxy.ErrorHandler = proxyErrorHandler
}

if psb.disableCertCheck {
proxy.Transport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
}

var server *http.Server

if psb.basicAuthEnabled {
Expand Down

0 comments on commit 5516660

Please sign in to comment.