diff options
author | Jaime Martinez <jmartinez@gitlab.com> | 2021-02-03 08:51:49 +0300 |
---|---|---|
committer | Jaime Martinez <jmartinez@gitlab.com> | 2021-02-08 02:52:07 +0300 |
commit | 9504871174848d6c3f47c6ba1d89899d1cd6c7f1 (patch) | |
tree | 05efc1f52a20e2691cdd95289a97396e59b09730 /internal/httprange/http_reader.go | |
parent | 4f07314b781e387183b29dff7d7ad62b9c111f26 (diff) |
Refactor http client usage in httprage
Moves the http.Client initialization inside the `httprange` package to
the zip VFS. This makes the type `Resource` depend on an http.Client
that needs to be passed on initialization.
It also makes the zip VFS initialize the client. It's possible to
reconfigure it to register a file protocol by calling vfs.Reconfigure
explicitly.
Diffstat (limited to 'internal/httprange/http_reader.go')
-rw-r--r-- | internal/httprange/http_reader.go | 20 |
1 files changed, 1 insertions, 19 deletions
diff --git a/internal/httprange/http_reader.go b/internal/httprange/http_reader.go index d1523177..c2b81b4d 100644 --- a/internal/httprange/http_reader.go +++ b/internal/httprange/http_reader.go @@ -6,9 +6,7 @@ import ( "fmt" "io" "net/http" - "time" - "gitlab.com/gitlab-org/gitlab-pages/internal/httptransport" "gitlab.com/gitlab-org/gitlab-pages/internal/vfs" "gitlab.com/gitlab-org/gitlab-pages/metrics" ) @@ -49,22 +47,6 @@ type Reader struct { // ensure that Reader is seekable var _ vfs.SeekableFile = &Reader{} -// TODO: make this configurable/take an http client when creating a reader/ranged reader -// instead https://gitlab.com/gitlab-org/gitlab-pages/-/issues/457 -var httpClient = &http.Client{ - // The longest time the request can be executed - Timeout: 30 * time.Minute, - Transport: httptransport.NewMeteredRoundTripper( - // TODO: register file protocol https://gitlab.com/gitlab-org/gitlab-pages/-/issues/485 - nil, - "httprange_client", - metrics.HTTPRangeTraceDuration, - metrics.HTTPRangeRequestDuration, - metrics.HTTPRangeRequestsTotal, - httptransport.DefaultTTFBTimeout, - ), -} - // ensureResponse is set before reading from it. // It will do the request if the reader hasn't got it yet. func (r *Reader) ensureResponse() error { @@ -79,7 +61,7 @@ func (r *Reader) ensureResponse() error { metrics.HTTPRangeOpenRequests.Inc() - res, err := httpClient.Do(req) + res, err := r.Resource.httpClient.Do(req) if err != nil { metrics.HTTPRangeOpenRequests.Dec() return err |