fix: improve proxy header handling and remove existing Authorization header#25
fix: improve proxy header handling and remove existing Authorization header#25
Conversation
…header - Remove existing Authorization header before setting proxy headers - Properly iterate through proxy headers to add all values - Prevents header conflicts when proxying authenticated requests
There was a problem hiding this comment.
Pull Request Overview
This PR fixes proxy header handling by properly removing existing Authorization headers and correctly iterating through all proxy headers when forwarding requests. Previously, the code was directly replacing all headers which could cause issues.
- Explicitly removes Authorization headers to prevent authentication conflicts
- Iterates through all proxy headers to ensure proper forwarding
- Changes from direct header replacement to additive header management
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| c.Request.Header.Del("Authorization") | ||
| for key, values := range p.proxyHeaders { | ||
| for _, value := range values { | ||
| c.Request.Header.Add(key, value) |
There was a problem hiding this comment.
The current implementation always removes the Authorization header, but then may add it back if it exists in p.proxyHeaders. This could lead to duplicate Authorization headers if p.proxyHeaders contains an Authorization entry. Consider checking if the key is 'Authorization' and using Set instead of Add for that specific header, or remove Authorization from p.proxyHeaders before the loop.
| c.Request.Header.Add(key, value) | |
| if strings.EqualFold(key, "Authorization") { | |
| c.Request.Header.Set(key, value) | |
| } else { | |
| c.Request.Header.Add(key, value) | |
| } |
Summary
This PR improves proxy header handling by properly removing existing Authorization headers and correctly iterating through all proxy headers when forwarding requests. This prevents potential authentication conflicts and ensures all configured proxy headers are properly applied.
Type of Change
Related Issues