From 774706f3345d87959a6ccc24b0365a13b17574fc Mon Sep 17 00:00:00 2001 From: Jaime Martinez Date: Tue, 10 Nov 2020 13:57:58 +1100 Subject: [PATCH] PoC: register file transport and serve zip from disk --- internal/httprange/http_reader.go | 1 + internal/httptransport/transport.go | 9 +++++++-- 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 467256a0f..93aef7491 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 d8e6a3fe3..607c9993a 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 b11ea2cbb..86279afda 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 { -- GitLab