Merge pull request #454 from gabriel-samfira/fix-encoding
Handle query args
This commit is contained in:
commit
c95252547e
1 changed files with 22 additions and 7 deletions
|
|
@ -19,9 +19,11 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
)
|
||||
|
||||
func (s *ScaleSetClient) newActionsRequest(ctx context.Context, method, path string, body io.Reader) (*http.Request, error) {
|
||||
func (s *ScaleSetClient) newActionsRequest(ctx context.Context, method, uriPath string, body io.Reader) (*http.Request, error) {
|
||||
if err := s.ensureAdminInfo(ctx); err != nil {
|
||||
return nil, fmt.Errorf("failed to update token: %w", err)
|
||||
}
|
||||
|
|
@ -31,14 +33,27 @@ func (s *ScaleSetClient) newActionsRequest(ctx context.Context, method, path str
|
|||
return nil, fmt.Errorf("failed to get pipeline URL: %w", err)
|
||||
}
|
||||
|
||||
uri := actionsURI.JoinPath(path)
|
||||
q := uri.Query()
|
||||
if q.Get("api-version") == "" {
|
||||
q.Set("api-version", "6.0-preview")
|
||||
pathURI, err := url.Parse(uriPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse path: %w", err)
|
||||
}
|
||||
pathQuery := pathURI.Query()
|
||||
baseQuery := actionsURI.Query()
|
||||
for k, values := range pathQuery {
|
||||
if baseQuery.Get(k) == "" {
|
||||
for _, val := range values {
|
||||
baseQuery.Add(k, val)
|
||||
}
|
||||
}
|
||||
}
|
||||
if baseQuery.Get("api-version") == "" {
|
||||
baseQuery.Set("api-version", "6.0-preview")
|
||||
}
|
||||
uri.RawQuery = q.Encode()
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, method, uri.String(), body)
|
||||
actionsURI.Path = path.Join(actionsURI.Path, pathURI.Path)
|
||||
actionsURI.RawQuery = baseQuery.Encode()
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, method, actionsURI.String(), body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue