diff options
author | Jaime Martinez <jmartinez@gitlab.com> | 2020-11-10 05:57:58 +0300 |
---|---|---|
committer | Jaime Martinez <jmartinez@gitlab.com> | 2020-11-10 05:57:58 +0300 |
commit | 774706f3345d87959a6ccc24b0365a13b17574fc (patch) | |
tree | 445bb690e183f46440ac156c8bf55fedbefacb41 | |
parent | b92c1fbca7c9ada076643bdf922db8951a5d0e91 (diff) |
PoC: register file transport and serve zip from diskpoc-add-file-transport-to-zip
-rw-r--r-- | internal/httprange/http_reader.go | 1 | ||||
-rw-r--r-- | internal/httptransport/transport.go | 9 | ||||
-rw-r--r-- | internal/source/gitlab/client/client.go | 24 |
3 files changed, 32 insertions, 2 deletions
diff --git a/internal/httprange/http_reader.go b/internal/httprange/http_reader.go index 467256a0..93aef749 100644 --- a/internal/httprange/http_reader.go +++ b/internal/httprange/http_reader.go @@ -63,6 +63,7 @@ var httpClient = &http.Client{ metrics.HTTPRangeRequestDuration, metrics.HTTPRangeRequestsTotal, httptransport.DefaultTTFBTimeout, + "/Users/jaime/dev/gitlab/ee/gitlab-pages/shared/pages", ), } diff --git a/internal/httptransport/transport.go b/internal/httptransport/transport.go index d8e6a3fe..607c9993 100644 --- a/internal/httptransport/transport.go +++ b/internal/httptransport/transport.go @@ -62,9 +62,14 @@ func newInternalTransport() *http.Transport { // NewTransportWithMetrics will create a custom http.RoundTripper that can be used with an http.Client. // The RoundTripper will report metrics based on the collectors passed. func NewTransportWithMetrics(name string, tracerVec, durationsVec *prometheus. - HistogramVec, counterVec *prometheus.CounterVec, ttfbTimeout time.Duration) http.RoundTripper { + HistogramVec, counterVec *prometheus.CounterVec, ttfbTimeout time.Duration, fsDir string) http.RoundTripper { + transport := InternalTransport + if fsDir != "" { + transport.RegisterProtocol("file", http.NewFileTransport(http.Dir(fsDir))) + } + return &meteredRoundTripper{ - next: InternalTransport, + next: transport, name: name, tracer: tracerVec, durations: durationsVec, diff --git a/internal/source/gitlab/client/client.go b/internal/source/gitlab/client/client.go index b11ea2cb..86279afd 100644 --- a/internal/source/gitlab/client/client.go +++ b/internal/source/gitlab/client/client.go @@ -62,6 +62,7 @@ func NewClient(baseURL string, secretKey []byte, connectionTimeout, jwtTokenExpi metrics.DomainsSourceAPICallDuration, metrics.DomainsSourceAPIReqTotal, httptransport.DefaultTTFBTimeout, + "", ), }, jwtTokenExpiry: jwtTokenExpiry, @@ -86,6 +87,29 @@ func (gc *Client) Resolve(ctx context.Context, host string) *api.Lookup { func (gc *Client) GetLookup(ctx context.Context, host string) api.Lookup { params := url.Values{} params.Set("host", host) + if host == "zip.pages.test" { + return api.Lookup{ + Name: "zip.pages.test", + Error: nil, + Domain: &api.VirtualDomain{ + Certificate: "", + Key: "", + LookupPaths: []api.LookupPath{ + api.LookupPath{ + ProjectID: 1234, + AccessControl: false, + HTTPSOnly: false, + Prefix: "/", + Source: api.Source{ + Type: "zip", + Path: "file:///group/zip.gitlab.io/public.zip", + Serverless: api.Serverless{}, + }, + }, + }, + }, + } + } resp, err := gc.get(ctx, "/api/v4/internal/pages", params) if err != nil { |