Skip to content

Commit

Permalink
feat: add support tls redirection for http proxy
Browse files Browse the repository at this point in the history
Signed-off-by: Jianhui Zhao <[email protected]>
  • Loading branch information
zhaojh329 committed Nov 22, 2024
1 parent b748584 commit 089dab6
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion http.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bufio"
"crypto/tls"
"encoding/binary"
"errors"
"fmt"
Expand Down Expand Up @@ -229,6 +230,17 @@ func listenHttpProxy(brk *broker) {
log.Fatal().Msg(err.Error())
}

if cfg.WebUISslCert != "" && cfg.WebUISslKey != "" {
crt, err := tls.LoadX509KeyPair(cfg.SslCert, cfg.SslKey)
if err != nil {
log.Fatal().Msg(err.Error())
}

tlsConfig := &tls.Config{Certificates: []tls.Certificate{crt}}

ln = tls.NewListener(ln, tlsConfig)
}

cfg.HttpProxyPort = ln.Addr().(*net.TCPAddr).Port

log.Info().Msgf("Listen http proxy on: %s", ln.Addr().(*net.TCPAddr))
Expand Down Expand Up @@ -302,7 +314,13 @@ func httpProxyRedirect(br *broker, c *gin.Context) {
if err != nil {
host = c.Request.Host
}
location = "http://" + host

if cfg.WebUISslCert != "" && cfg.WebUISslKey != "" {
location = "https://" + host
} else {
location = "http://" + host
}

if cfg.HttpProxyPort != 80 {
location += fmt.Sprintf(":%d", cfg.HttpProxyPort)
}
Expand Down

0 comments on commit 089dab6

Please sign in to comment.