blob: b94dcdcff820084b99d91ea4c49dd6945100b3d9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
package handlers
import (
"net/http"
"time"
"gitlab.com/gitlab-org/gitlab-pages/internal/domain"
"gitlab.com/gitlab-org/gitlab-pages/metrics"
)
// ServeFileOrNotFound will serve static content or
// return a 404 Not Found response
func (h *Handlers) ServeFileOrNotFound() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
defer metrics.ServingTime.Observe(time.Since(start).Seconds())
d := domain.FromRequest(r)
fileServed := d.ServeFileHTTP(w, r)
if !fileServed {
// We need to trigger authentication flow here if file does not exist to prevent exposing possibly private project existence,
// because the projects override the paths of the namespace project and they might be private even though
// namespace project is public
if d.IsNamespaceProject(r) {
if h.Auth.CheckAuthenticationWithoutProject(w, r, d) {
return
}
}
// d found and authentication succeeds
d.ServeNotFoundHTTP(w, r)
}
})
}
|