Skip to content

Commit

Permalink
Pull request: 4993-alt-svc
Browse files Browse the repository at this point in the history
Updates AdguardTeam#4986.
Updates AdguardTeam#4993.

* commit 'd42d1a7ea48850a97f6ab74c181e4348885a4068':
  all: imp chlog; dry; fix races
  updated changelog
  changes done based on review
  referred https port from config
  added h3 header
  • Loading branch information
ainar-g committed Oct 10, 2022
2 parents 0eba31c + d42d1a7 commit 67da002
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ and this project adheres to
opposed to URL paths ([#3418]). Note that AdGuard Home checks the server name
only if the URL does not contain a ClientID.

### Fixed

- Web UI not switching to HTTP/3 ([#4986], [#4993]).

[#3418]: https://github.com/AdguardTeam/AdGuardHome/issues/3418
[#4986]: https://github.com/AdguardTeam/AdGuardHome/issues/4986
[#4993]: https://github.com/AdguardTeam/AdGuardHome/issues/4993

[clientid]: https://github.com/AdguardTeam/AdGuardHome/wiki/Clients#clientid

Expand Down
3 changes: 3 additions & 0 deletions internal/aghhttp/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ package aghhttp
const (
HdrNameAcceptEncoding = "Accept-Encoding"
HdrNameAccessControlAllowOrigin = "Access-Control-Allow-Origin"
HdrNameAltSvc = "Alt-Svc"
HdrNameContentEncoding = "Content-Encoding"
HdrNameContentType = "Content-Type"
HdrNameOrigin = "Origin"
HdrNameServer = "Server"
HdrNameTrailer = "Trailer"
HdrNameUserAgent = "User-Agent"
HdrNameVary = "Vary"
)

// HTTP header value constants.
Expand Down
27 changes: 25 additions & 2 deletions internal/home/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,28 @@ func handleHTTPSRedirect(w http.ResponseWriter, r *http.Request) (ok bool) {
return false
}

var serveHTTP3 bool
var portHTTPS int
func() {
config.RLock()
defer config.RUnlock()

serveHTTP3, portHTTPS = config.DNS.ServeHTTP3, config.TLS.PortHTTPS
}()

respHdr := w.Header()

// Let the browser know that server supports HTTP/3.
//
// See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Alt-Svc.
//
// TODO(a.garipov): Consider adding a configurable max-age. Currently, the
// default is 24 hours.
if serveHTTP3 {
altSvc := fmt.Sprintf(`h3=":%d"`, portHTTPS)
respHdr.Set(aghhttp.HdrNameAltSvc, altSvc)
}

if r.TLS == nil && web.forceHTTPS {
hostPort := host
if port := web.conf.PortHTTPS; port != defaultPortHTTPS {
Expand All @@ -346,8 +368,9 @@ func handleHTTPSRedirect(w http.ResponseWriter, r *http.Request) (ok bool) {
Scheme: aghhttp.SchemeHTTP,
Host: r.Host,
}
w.Header().Set("Access-Control-Allow-Origin", originURL.String())
w.Header().Set("Vary", "Origin")

respHdr.Set(aghhttp.HdrNameAccessControlAllowOrigin, originURL.String())
respHdr.Set(aghhttp.HdrNameVary, aghhttp.HdrNameOrigin)

return true
}
Expand Down

0 comments on commit 67da002

Please sign in to comment.