diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-08-26 08:15:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-08-26 08:15:20 +0000 |
commit | 87d772a7d708fec12f48cd8adc0dedff6e1025da (patch) | |
tree | 1fee344c64cc3f43074a01981e21126c8482a522 /src/go/collectors/go.d.plugin/pkg/web | |
parent | Adding upstream version 1.46.3. (diff) | |
download | netdata-87d772a7d708fec12f48cd8adc0dedff6e1025da.tar.xz netdata-87d772a7d708fec12f48cd8adc0dedff6e1025da.zip |
Adding upstream version 1.47.0.upstream/1.47.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/go/plugin/go.d/pkg/web/client.go (renamed from src/go/collectors/go.d.plugin/pkg/web/client.go) | 2 | ||||
-rw-r--r-- | src/go/plugin/go.d/pkg/web/client_test.go (renamed from src/go/collectors/go.d.plugin/pkg/web/client_test.go) | 0 | ||||
-rw-r--r-- | src/go/plugin/go.d/pkg/web/doc.go (renamed from src/go/collectors/go.d.plugin/pkg/web/doc.go) | 0 | ||||
-rw-r--r-- | src/go/plugin/go.d/pkg/web/doc_test.go (renamed from src/go/collectors/go.d.plugin/pkg/web/doc_test.go) | 0 | ||||
-rw-r--r-- | src/go/plugin/go.d/pkg/web/duration.go (renamed from src/go/collectors/go.d.plugin/pkg/web/duration.go) | 0 | ||||
-rw-r--r-- | src/go/plugin/go.d/pkg/web/duration_test.go (renamed from src/go/collectors/go.d.plugin/pkg/web/duration_test.go) | 0 | ||||
-rw-r--r-- | src/go/plugin/go.d/pkg/web/request.go (renamed from src/go/collectors/go.d.plugin/pkg/web/request.go) | 17 | ||||
-rw-r--r-- | src/go/plugin/go.d/pkg/web/request_test.go (renamed from src/go/collectors/go.d.plugin/pkg/web/request_test.go) | 28 | ||||
-rw-r--r-- | src/go/plugin/go.d/pkg/web/web.go (renamed from src/go/collectors/go.d.plugin/pkg/web/web.go) | 0 |
9 files changed, 44 insertions, 3 deletions
diff --git a/src/go/collectors/go.d.plugin/pkg/web/client.go b/src/go/plugin/go.d/pkg/web/client.go index 1de75230d..02dc17de1 100644 --- a/src/go/collectors/go.d.plugin/pkg/web/client.go +++ b/src/go/plugin/go.d/pkg/web/client.go @@ -9,7 +9,7 @@ import ( "net/http" "net/url" - "github.com/netdata/netdata/go/go.d.plugin/pkg/tlscfg" + "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/tlscfg" ) // ErrRedirectAttempted indicates that a redirect occurred. diff --git a/src/go/collectors/go.d.plugin/pkg/web/client_test.go b/src/go/plugin/go.d/pkg/web/client_test.go index ead1486c3..ead1486c3 100644 --- a/src/go/collectors/go.d.plugin/pkg/web/client_test.go +++ b/src/go/plugin/go.d/pkg/web/client_test.go diff --git a/src/go/collectors/go.d.plugin/pkg/web/doc.go b/src/go/plugin/go.d/pkg/web/doc.go index 4c6d31461..4c6d31461 100644 --- a/src/go/collectors/go.d.plugin/pkg/web/doc.go +++ b/src/go/plugin/go.d/pkg/web/doc.go diff --git a/src/go/collectors/go.d.plugin/pkg/web/doc_test.go b/src/go/plugin/go.d/pkg/web/doc_test.go index 137eed207..137eed207 100644 --- a/src/go/collectors/go.d.plugin/pkg/web/doc_test.go +++ b/src/go/plugin/go.d/pkg/web/doc_test.go diff --git a/src/go/collectors/go.d.plugin/pkg/web/duration.go b/src/go/plugin/go.d/pkg/web/duration.go index 85d5ef650..85d5ef650 100644 --- a/src/go/collectors/go.d.plugin/pkg/web/duration.go +++ b/src/go/plugin/go.d/pkg/web/duration.go diff --git a/src/go/collectors/go.d.plugin/pkg/web/duration_test.go b/src/go/plugin/go.d/pkg/web/duration_test.go index b45063f13..b45063f13 100644 --- a/src/go/collectors/go.d.plugin/pkg/web/duration_test.go +++ b/src/go/plugin/go.d/pkg/web/duration_test.go diff --git a/src/go/collectors/go.d.plugin/pkg/web/request.go b/src/go/plugin/go.d/pkg/web/request.go index e8e4b742a..20a6ec093 100644 --- a/src/go/collectors/go.d.plugin/pkg/web/request.go +++ b/src/go/plugin/go.d/pkg/web/request.go @@ -7,10 +7,11 @@ import ( "fmt" "io" "net/http" + "net/url" "strings" - "github.com/netdata/netdata/go/go.d.plugin/agent/executable" - "github.com/netdata/netdata/go/go.d.plugin/pkg/buildinfo" + "github.com/netdata/netdata/go/plugins/pkg/buildinfo" + "github.com/netdata/netdata/go/plugins/pkg/executable" ) // Request is the configuration of the HTTP request. @@ -90,3 +91,15 @@ func NewHTTPRequest(cfg Request) (*http.Request, error) { return req, nil } + +func NewHTTPRequestWithPath(cfg Request, urlPath string) (*http.Request, error) { + cfg = cfg.Copy() + + v, err := url.JoinPath(cfg.URL, urlPath) + if err != nil { + return nil, fmt.Errorf("failed to join URL path: %v", err) + } + cfg.URL = v + + return NewHTTPRequest(cfg) +} diff --git a/src/go/collectors/go.d.plugin/pkg/web/request_test.go b/src/go/plugin/go.d/pkg/web/request_test.go index 284cccb93..d39f9a36a 100644 --- a/src/go/collectors/go.d.plugin/pkg/web/request_test.go +++ b/src/go/plugin/go.d/pkg/web/request_test.go @@ -159,6 +159,34 @@ func TestNewHTTPRequest(t *testing.T) { } } +func TestNewRequest(t *testing.T) { + tests := map[string]struct { + url string + path string + wantURL string + }{ + "base url": { + url: "http://127.0.0.1:65535", + path: "/bar", + wantURL: "http://127.0.0.1:65535/bar", + }, + "with path": { + url: "http://127.0.0.1:65535/foo/", + path: "/bar", + wantURL: "http://127.0.0.1:65535/foo/bar", + }, + } + + for name, test := range tests { + t.Run(name, func(t *testing.T) { + req, err := NewHTTPRequestWithPath(Request{URL: test.url}.Copy(), test.path) + require.NoError(t, err) + + assert.Equal(t, test.wantURL, req.URL.String()) + }) + } +} + func parseBasicAuth(auth string) (username, password string, ok bool) { const prefix = "Basic " if len(auth) < len(prefix) || !strings.EqualFold(auth[:len(prefix)], prefix) { diff --git a/src/go/collectors/go.d.plugin/pkg/web/web.go b/src/go/plugin/go.d/pkg/web/web.go index cbda396d4..cbda396d4 100644 --- a/src/go/collectors/go.d.plugin/pkg/web/web.go +++ b/src/go/plugin/go.d/pkg/web/web.go |