diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2019-02-28 18:05:02 +0300 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2019-02-28 18:05:02 +0300 |
commit | b2c04825bbbea923e03cd004d8a77ed1ab142aac (patch) | |
tree | b92fd2e3c28d36ec0243e4b59760d4cea2ac46cb /internal/client | |
parent | a6d5eb8ecac9f3f74f156037d200dff620b2fa2c (diff) |
Request configuration from API
Diffstat (limited to 'internal/client')
-rw-r--r-- | internal/client/api.go | 5 | ||||
-rw-r--r-- | internal/client/domain_response.go | 2 | ||||
-rw-r--r-- | internal/client/lookup_path.go | 8 | ||||
-rw-r--r-- | internal/client/mock_api.go | 64 |
4 files changed, 75 insertions, 4 deletions
diff --git a/internal/client/api.go b/internal/client/api.go index 5566f151..573123e0 100644 --- a/internal/client/api.go +++ b/internal/client/api.go @@ -7,8 +7,9 @@ import ( ) func RequestDomain(apiUrl, host string) *DomainResponse { - var values url.Values - values.Add("host", host) + values := url.Values{ + "host": []string{host}, + } resp, err := http.PostForm(apiUrl+"/pages/domain", values) if err != nil { diff --git a/internal/client/domain_response.go b/internal/client/domain_response.go index 77d9b474..6a273ce9 100644 --- a/internal/client/domain_response.go +++ b/internal/client/domain_response.go @@ -15,7 +15,7 @@ type DomainResponse struct { func (d *DomainResponse) GetPath(r *http.Request) *LookupPath { for _, lp := range d.LookupPath { - if strings.HasPrefix(r.RequestURI, lp.Prefix) { + if strings.HasPrefix(r.URL.Path, lp.Prefix) { return &lp } } diff --git a/internal/client/lookup_path.go b/internal/client/lookup_path.go index f11dd925..52506d1c 100644 --- a/internal/client/lookup_path.go +++ b/internal/client/lookup_path.go @@ -10,6 +10,9 @@ import ( "golang.org/x/sys/unix" ) +// TODO: This is hack to pass the location +var RootPath string + type LookupConfig struct { NamespaceProject bool `json:"namespace_project"` HTTPSOnly bool `json:"https_only"` @@ -26,7 +29,7 @@ type LookupPath struct { func (lp *LookupPath) Tail(r *http.Request) string { if strings.HasPrefix(r.URL.Path, lp.Prefix) { - return r.URL.Path[len(lp.Path):] + return r.URL.Path[len(lp.Prefix):] } return "" @@ -49,6 +52,7 @@ func (lp *LookupPath) resolvePath(path string) (string, error) { func (lp *LookupPath) Resolve(path string) (string, error) { fullPath, err := lp.resolvePath(path) + println("LookupPath::Resolve", lp.Path, path, fullPath, err) if err != nil { return "", err } @@ -58,6 +62,7 @@ func (lp *LookupPath) Resolve(path string) (string, error) { func (lp *LookupPath) Stat(path string) (os.FileInfo, error) { fullPath, err := lp.resolvePath(path) + println("LookupPath::Stat", lp.Path, path, fullPath, err) if err != nil { return nil, err } @@ -67,6 +72,7 @@ func (lp *LookupPath) Stat(path string) (os.FileInfo, error) { func (lp *LookupPath) Open(path string) (*os.File, error) { fullPath, err := lp.resolvePath(path) + println("LookupPath::Open", lp.Path, path, fullPath, err) if err != nil { return nil, err } diff --git a/internal/client/mock_api.go b/internal/client/mock_api.go new file mode 100644 index 00000000..623e80aa --- /dev/null +++ b/internal/client/mock_api.go @@ -0,0 +1,64 @@ +package client + +var internalConfigs = map[string]DomainResponse{ + "group.internal.gitlab-example.com": DomainResponse{ + LookupPath: []LookupPath{ + LookupPath{ + Prefix: "/project.internal/", + Path: "group.internal/project.internal/public", + }, + }, + }, + "group.404.gitlab-example.com": DomainResponse{ + LookupPath: []LookupPath{ + LookupPath{ + Prefix: "/project.no.404/", + Path: "group.404/project.no.404/public/", + }, + LookupPath{ + Prefix: "/project.404/", + Path: "group.404/project.404/public/", + }, + LookupPath{ + Prefix: "/project.404.symlink/", + Path: "group.404/project.404.symlink/public/", + }, + LookupPath{ + Prefix: "/domain.404/", + Path: "group.404/domain.404/public/", + }, + LookupPath{ + Prefix: "/group.404.test.io/", + Path: "group.404/group.404.test.io/public/", + }, + }, + }, + "group.gitlab-example.io": DomainResponse{ + LookupPath: []LookupPath{ + LookupPath{ + Prefix: "/group.test.io/", + Path: "group/group.test.io/public/", + }, + LookupPath{ + Prefix: "/", + Path: "group/group.gitlab-example.io/public/", + }, + }, + }, + "group.test.io": DomainResponse{ + LookupPath: []LookupPath{ + LookupPath{ + Prefix: "/", + Path: "group/group.test.io/public/", + }, + }, + }, +} + +func MockRequestDomain(apiUrl, host string) *DomainResponse { + if response, ok := internalConfigs[host]; ok { + println("Requested", host) + return &response + } + return nil +} |