Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app.go
diff options
context:
space:
mode:
Diffstat (limited to 'app.go')
-rw-r--r--app.go22
1 files changed, 16 insertions, 6 deletions
diff --git a/app.go b/app.go
index 7c927dfe..f64421a4 100644
--- a/app.go
+++ b/app.go
@@ -61,7 +61,7 @@ func (a *theApp) ServeTLS(ch *tls.ClientHelloInfo) (*tls.Certificate, error) {
return nil, nil
}
- if domain := a.domain(ch.ServerName); domain != nil {
+ if domain, _ := a.domain(ch.ServerName); domain != nil {
tls, _ := domain.EnsureCertificate()
return tls, nil
}
@@ -86,16 +86,18 @@ func (a *theApp) redirectToHTTPS(w http.ResponseWriter, r *http.Request, statusC
http.Redirect(w, r, u.String(), statusCode)
}
-func (a *theApp) getHostAndDomain(r *http.Request) (host string, domain *domain.Domain) {
+func (a *theApp) getHostAndDomain(r *http.Request) (string, *domain.Domain, error) {
host, _, err := net.SplitHostPort(r.Host)
if err != nil {
host = r.Host
}
- return host, a.domain(host)
+ domain, err := a.domain(host)
+
+ return host, domain, err
}
-func (a *theApp) domain(host string) *domain.Domain {
+func (a *theApp) domain(host string) (*domain.Domain, error) {
return a.domains.GetDomain(host)
}
@@ -163,7 +165,15 @@ func (a *theApp) tryAuxiliaryHandlers(w http.ResponseWriter, r *http.Request, ht
// downstream middlewares to use
func (a *theApp) routingMiddleware(handler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- host, domain := a.getHostAndDomain(r)
+ // if we could not retrieve a domain from domains source we break the
+ // middleware chain and simply respond with 502 after logging this
+ host, domain, err := a.getHostAndDomain(r)
+ if err != nil {
+ log.WithError(err).Error("could not fetch domain information from a source")
+
+ httperrors.Serve502(w)
+ return
+ }
r = request.WithHostAndDomain(r, host, domain)
@@ -289,7 +299,7 @@ func (a *theApp) proxyInitialMiddleware(handler http.Handler) http.Handler {
}
func (a *theApp) buildHandlerPipeline() (http.Handler, error) {
- // Handlers should be applied in reverse order
+ // Handlers should be applied in a reverse order
handler := a.serveFileOrNotFoundHandler()
if !a.DisableCrossOriginRequests {
handler = corsHandler.Handler(handler)