Enhance httpsrv TLS redirect options#151
Open
Eric-Guo wants to merge 1 commit into
Open
Conversation
Add non-standard HTTPS redirect port support and multi-domain whitelist options for auto-encrypt TLS mode.
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds support for multiple domains in the autocert host whitelist and makes HTTP→HTTPS redirects aware of a configurable HTTPS port.
Changes:
- Extend TLS auto-encrypt options/config to support additional whitelisted domains.
- Add
redirectHTTPSPortoption and implement a custom redirect handler used byautocert.Manager.HTTPHandler. - Update docs and tests to cover extra domains + redirect port behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| pkg/httpsrv/tls_auto_encrypt.go | Adds domain normalization/whitelisting and configurable redirect HTTPS port via a custom redirect handler. |
| pkg/httpsrv/tls_auto_encrypt_test.go | Expands option validation tests and adds redirect handler tests (including custom port). |
| pkg/httpsrv/README.md | Documents new redirect HTTPS port and extra domains options. |
| pkg/httpsrv/readme-cn.md | Mirrors README changes in Chinese documentation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+179
to
+192
| host := strings.TrimSpace(r.Host) | ||
| if parsedHost, _, err := net.SplitHostPort(host); err == nil && parsedHost != "" { | ||
| host = parsedHost | ||
| } | ||
| if host == "" && r.URL != nil { | ||
| host = r.URL.Host | ||
| } | ||
|
|
||
| targetHost := host | ||
| if host != "" && c.redirectHTTPSPort > 0 && c.redirectHTTPSPort != 443 { | ||
| targetHost = net.JoinHostPort(host, strconv.Itoa(c.redirectHTTPSPort)) | ||
| } | ||
|
|
||
| http.Redirect(w, r, "https://"+targetHost+r.URL.RequestURI(), http.StatusFound) |
Comment on lines
+183
to
+192
| if host == "" && r.URL != nil { | ||
| host = r.URL.Host | ||
| } | ||
|
|
||
| targetHost := host | ||
| if host != "" && c.redirectHTTPSPort > 0 && c.redirectHTTPSPort != 443 { | ||
| targetHost = net.JoinHostPort(host, strconv.Itoa(c.redirectHTTPSPort)) | ||
| } | ||
|
|
||
| http.Redirect(w, r, "https://"+targetHost+r.URL.RequestURI(), http.StatusFound) |
Comment on lines
+205
to
+220
| func normalizeDomains(domains []string) []string { | ||
| seen := map[string]struct{}{} | ||
| filtered := make([]string, 0, len(domains)) | ||
| for _, domain := range domains { | ||
| domain = strings.TrimSpace(domain) | ||
| if domain == "" { | ||
| continue | ||
| } | ||
| if _, ok := seen[domain]; ok { | ||
| continue | ||
| } | ||
| seen[domain] = struct{}{} | ||
| filtered = append(filtered, domain) | ||
| } | ||
| return filtered | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add non-standard HTTPS redirect port support and multi-domain whitelist options for auto-encrypt TLS mode.
Used at Eric-Guo/thrustOauth2idServer#2