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:
authorJaime Martinez <jmartinez@gitlab.com>2021-02-03 08:51:49 +0300
committerJaime Martinez <jmartinez@gitlab.com>2021-02-08 02:52:07 +0300
commit9504871174848d6c3f47c6ba1d89899d1cd6c7f1 (patch)
tree05efc1f52a20e2691cdd95289a97396e59b09730 /internal/httprange/resource.go
parent4f07314b781e387183b29dff7d7ad62b9c111f26 (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/resource.go')
-rw-r--r--internal/httprange/resource.go7
1 files changed, 5 insertions, 2 deletions
diff --git a/internal/httprange/resource.go b/internal/httprange/resource.go
index 8b908fe8..4ef5f0ea 100644
--- a/internal/httprange/resource.go
+++ b/internal/httprange/resource.go
@@ -20,6 +20,8 @@ type Resource struct {
url atomic.Value
err atomic.Value
+
+ httpClient *http.Client
}
func (r *Resource) URL() string {
@@ -67,8 +69,8 @@ func (r *Resource) Request() (*http.Request, error) {
return req, nil
}
-func NewResource(ctx context.Context, url string) (*Resource, error) {
- // the `h.URL` is likely pre-signed URL that only supports GET requests
+func NewResource(ctx context.Context, url string, httpClient *http.Client) (*Resource, error) {
+ // the `h.URL` is likely pre-signed URL or a file:// scheme that only supports GET requests
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
@@ -94,6 +96,7 @@ func NewResource(ctx context.Context, url string) (*Resource, error) {
resource := &Resource{
ETag: res.Header.Get("ETag"),
LastModified: res.Header.Get("Last-Modified"),
+ httpClient: httpClient,
}
resource.SetURL(url)