Added additional headers to config
This commit is contained in:
@@ -24,6 +24,7 @@ type Config struct {
|
|||||||
Domains []string `yaml:"domains"`
|
Domains []string `yaml:"domains"`
|
||||||
Secure bool `yaml:"secure"`
|
Secure bool `yaml:"secure"`
|
||||||
Rewrite map[string]string `yaml:"rewrite"`
|
Rewrite map[string]string `yaml:"rewrite"`
|
||||||
|
AdditionalHeaders map[string]string `yaml:"extraHeaders"`
|
||||||
} `yaml:"hosts"`
|
} `yaml:"hosts"`
|
||||||
RateLimit struct {
|
RateLimit struct {
|
||||||
Enabled bool `yaml:"enabled"`
|
Enabled bool `yaml:"enabled"`
|
||||||
|
|||||||
20
router.go
20
router.go
@@ -29,13 +29,14 @@ type Host struct {
|
|||||||
Secure bool
|
Secure bool
|
||||||
Current *atomic.Uint32
|
Current *atomic.Uint32
|
||||||
Rewrites map[string]*Host
|
Rewrites map[string]*Host
|
||||||
|
AdditionalHeaders map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(config *Config, client *http.Client) Router {
|
func New(config *Config, client *http.Client) Router {
|
||||||
m := make(map[string]Host)
|
m := make(map[string]Host)
|
||||||
for _, host := range config.Hosts {
|
for _, host := range config.Hosts {
|
||||||
for _, domain := range host.Domains {
|
for _, domain := range host.Domains {
|
||||||
curr := Host{host.Port, host.Remotes, host.Secure, &atomic.Uint32{}, make(map[string]*Host)}
|
curr := Host{host.Port, host.Remotes, host.Secure, &atomic.Uint32{}, make(map[string]*Host), host.AdditionalHeaders}
|
||||||
m[domain] = curr
|
m[domain] = curr
|
||||||
|
|
||||||
for subUrl, rewriteHost := range host.Rewrite {
|
for subUrl, rewriteHost := range host.Rewrite {
|
||||||
@@ -98,17 +99,6 @@ func (router *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for subUrl, rewriteHost := range host.Rewrites {
|
for subUrl, rewriteHost := range host.Rewrites {
|
||||||
// parts := strings.Split(subUrl, "/")
|
|
||||||
// requestParts := strings.Split(r.URL.Path, "/")
|
|
||||||
//
|
|
||||||
// for i, part := range parts {
|
|
||||||
// if !strings.EqualFold(part, requestParts[i]) {
|
|
||||||
// break
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// slicedPath := "/" + strings.Join(requestParts[len(parts):], "/")
|
|
||||||
|
|
||||||
if !strings.HasPrefix(r.URL.Path, subUrl) {
|
if !strings.HasPrefix(r.URL.Path, subUrl) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -212,7 +202,11 @@ func (router *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
removeHopByHopHeaders(res.Header)
|
removeHopByHopHeaders(res.Header)
|
||||||
|
|
||||||
copyHeader(w.Header(), res.Header)
|
resultHeader := w.Header()
|
||||||
|
copyHeader(resultHeader, res.Header)
|
||||||
|
for name, val := range host.AdditionalHeaders {
|
||||||
|
resultHeader.Add(name, val)
|
||||||
|
}
|
||||||
|
|
||||||
w.WriteHeader(res.StatusCode)
|
w.WriteHeader(res.StatusCode)
|
||||||
err = router.copyResponse(w, res.Body)
|
err = router.copyResponse(w, res.Body)
|
||||||
|
|||||||
Reference in New Issue
Block a user