Skip to content

Commit

Permalink
chore(proxy): restructure proxy headers logic
Browse files Browse the repository at this point in the history
  • Loading branch information
unkn0wn-root committed Dec 30, 2024
1 parent 7e20163 commit e0d9fa6
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions internal/pool/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,11 @@ func (p *URLRewriteProxy) updateRequestHeaders(req *http.Request) {
req.Header.Set(HeaderXForwardedHost, originalHost)
req.Header.Set(HeaderXForwardedFor, originalHost)

hc := p.headerConfig
if hc != nil {
if hc := p.headerConfig; hc != nil {
for _, header := range hc.RemoveRequestHeaders {
req.Header.Del(header)
}

// Add/modify configured request headers
for key, value := range hc.RequestHeaders {
processedValue := p.processHeaderValue(value, req)
req.Header.Set(key, processedValue)
Expand Down Expand Up @@ -231,14 +229,11 @@ func (p *URLRewriteProxy) updateResponseHeaders(resp *http.Response) {
resp.Header.Del(HeaderXPoweredBy)
resp.Header.Set(HeaderXProxyBy, DefaultProxyLabel)

hc := p.headerConfig
if hc != nil {
// Remove specified response headers
if hc := p.headerConfig; hc != nil {
for _, header := range hc.RemoveResponseHeaders {
resp.Header.Del(header)
}

// Add/modify configured response headers
for key, value := range hc.ResponseHeaders {
processedValue := p.processHeaderValue(value, resp.Request)
resp.Header.Set(key, processedValue)
Expand Down Expand Up @@ -274,6 +269,7 @@ func (p *URLRewriteProxy) errorHandler(w http.ResponseWriter, r *http.Request, e
}

// processHeaderValue replaces placeholder values with actual req values
// if string placeholders in not being used - it returns value back
func (p *URLRewriteProxy) processHeaderValue(value string, req *http.Request) string {
// Replace placeholders with actual values
placeholders := map[string]func(*http.Request) string{
Expand Down

0 comments on commit e0d9fa6

Please sign in to comment.