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
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2020-02-03 18:17:56 +0300
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2020-02-05 14:00:21 +0300
commit4d5764a77935ef502e34fed33f74e69ba1cebc6b (patch)
treec17b25be29c63ab9c3613f548f89b27153d2d552
parent57a8b1184da1d53184aad5d4f0bedea51d330b1a (diff)
Add support for per-lookup-path domain serving
-rw-r--r--internal/domain/domain.go21
-rw-r--r--internal/serving/handler.go14
-rw-r--r--internal/serving/lookup_path.go20
-rw-r--r--internal/source/gitlab/gitlab.go9
4 files changed, 40 insertions, 24 deletions
diff --git a/internal/domain/domain.go b/internal/domain/domain.go
index 28eb3196..6e6ffde0 100644
--- a/internal/domain/domain.go
+++ b/internal/domain/domain.go
@@ -19,8 +19,6 @@ type Domain struct {
Resolver Resolver
- serving serving.Serving
-
certificate *tls.Certificate
certificateError error
certificateOnce sync.Once
@@ -57,16 +55,8 @@ func (d *Domain) GetLookupPath(r *http.Request) *serving.LookupPath {
return lookupPath
}
-// Serving returns domain serving driver
-func (d *Domain) Serving() serving.Serving {
- if d.serving == nil {
- d.serving = disk.New()
- }
-
- return d.serving
-}
-
-func (d *Domain) toHandler(w http.ResponseWriter, r *http.Request) serving.Handler {
+// Handler returns a serving handler for this request
+func (d *Domain) Handler(w http.ResponseWriter, r *http.Request) serving.Handler {
project, subpath := d.resolve(r)
return serving.Handler{
@@ -74,6 +64,7 @@ func (d *Domain) toHandler(w http.ResponseWriter, r *http.Request) serving.Handl
Request: r,
LookupPath: project,
SubPath: subpath,
+ Serving: disk.New(),
}
}
@@ -168,7 +159,8 @@ func (d *Domain) ServeFileHTTP(w http.ResponseWriter, r *http.Request) bool {
return true
}
- return d.Serving().ServeFileHTTP(d.toHandler(w, r))
+ return d.Handler(w, r).ServeFileHTTP()
+ //d.Serving().ServeFileHTTP(d.toHandler(w, r))
}
// ServeNotFoundHTTP serves the not found pages from the projects.
@@ -178,5 +170,6 @@ func (d *Domain) ServeNotFoundHTTP(w http.ResponseWriter, r *http.Request) {
return
}
- d.Serving().ServeNotFoundHTTP(d.toHandler(w, r))
+ d.Handler(w, r).ServeNotFoundHTTP()
+ //d.Serving().ServeNotFoundHTTP(d.toHandler(w, r))
}
diff --git a/internal/serving/handler.go b/internal/serving/handler.go
index 99c4ca2f..a18fce7b 100644
--- a/internal/serving/handler.go
+++ b/internal/serving/handler.go
@@ -8,6 +8,16 @@ type Handler struct {
Writer http.ResponseWriter
Request *http.Request
LookupPath *LookupPath
- // Parsed representation of Request.URI that is part of LookupPath.Prefix
- SubPath string
+ Serving Serving
+ SubPath string
+}
+
+// ServeFileHTTP passes the handler itself to a serving function
+func (h Handler) ServeFileHTTP() bool {
+ return h.Serving.ServeFileHTTP(h)
+}
+
+// ServeNotFoundHTTP passes the handler itself to a serving function
+func (h Handler) ServeNotFoundHTTP() {
+ h.Serving.ServeNotFoundHTTP(h)
}
diff --git a/internal/serving/lookup_path.go b/internal/serving/lookup_path.go
index 4360358b..492d3995 100644
--- a/internal/serving/lookup_path.go
+++ b/internal/serving/lookup_path.go
@@ -1,5 +1,11 @@
package serving
+import (
+ "strings"
+
+ "gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/api"
+)
+
// LookupPath holds a domain project configuration needed to handle a request
type LookupPath struct {
Prefix string // Project prefix, for example, /my/project in group.gitlab.io/my/project/index.html
@@ -9,3 +15,17 @@ type LookupPath struct {
HasAccessControl bool
ProjectID uint64
}
+
+// NewLookupPath fabricates a new serving lookup path based on a API response.
+// `lookups` argument is a temporary workaround for
+// https://gitlab.com/gitlab-org/gitlab-pages/issues/272
+func NewLookupPath(lookups int, lookup api.LookupPath) *LookupPath {
+ return &LookupPath{
+ Prefix: lookup.Prefix,
+ Path: strings.TrimPrefix(lookup.Source.Path, "/"),
+ IsNamespaceProject: (lookup.Prefix == "/" && lookups > 1),
+ IsHTTPSOnly: lookup.HTTPSOnly,
+ HasAccessControl: lookup.AccessControl,
+ ProjectID: uint64(lookup.ProjectID),
+ }
+}
diff --git a/internal/source/gitlab/gitlab.go b/internal/source/gitlab/gitlab.go
index cce70733..79b58501 100644
--- a/internal/source/gitlab/gitlab.go
+++ b/internal/source/gitlab/gitlab.go
@@ -72,14 +72,7 @@ func (g *Gitlab) Resolve(r *http.Request) (*serving.LookupPath, string, error) {
isRootPath := urlPath == path.Clean(lookup.Prefix)
if isSubPath || isRootPath {
- lookupPath := &serving.LookupPath{
- Prefix: lookup.Prefix,
- Path: strings.TrimPrefix(lookup.Source.Path, "/"),
- IsNamespaceProject: (lookup.Prefix == "/" && len(response.Domain.LookupPaths) > 1),
- IsHTTPSOnly: lookup.HTTPSOnly,
- HasAccessControl: lookup.AccessControl,
- ProjectID: uint64(lookup.ProjectID),
- }
+ lookupPath := serving.NewLookupPath(len(response.Domain.LookupPaths), lookup)
subPath := ""
if isSubPath {