Skip to content

Commit

Permalink
refactor(oauth): use constructor for new client in comm.HTTPClient.JS…
Browse files Browse the repository at this point in the history
…ONCall

Parsing the url, then setting qv.Encode() manually to u.RawQuery
feel like an overcomplicated approach of creating url for http request.

Use the native constructor, which enforces ctx to be
passed into the request, and do simple sprintf for url + query.
  • Loading branch information
handsomejack-42 authored and bgavrilMS committed Nov 5, 2024
1 parent fc5a751 commit a9d2090
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions apps/internal/oauth/ops/internal/comm/comm.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import (
"strings"
"time"

"github.com/google/uuid"

"github.com/AzureAD/microsoft-authentication-library-for-go/apps/errors"
customJSON "github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/json"
"github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/version"
"github.com/google/uuid"
)

// HTTPClient represents an HTTP client.
Expand Down Expand Up @@ -70,15 +71,13 @@ func (c *Client) JSONCall(ctx context.Context, endpoint string, headers http.Hea
unmarshal = customJSON.Unmarshal
}

u, err := url.Parse(endpoint)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("%s?%s", endpoint, qv.Encode()), nil)
if err != nil {
return fmt.Errorf("could not parse path URL(%s): %w", endpoint, err)
return fmt.Errorf("could not create request: %w", err)
}
u.RawQuery = qv.Encode()

addStdHeaders(headers)

req := &http.Request{Method: http.MethodGet, URL: u, Header: headers}
req.Header = headers

if body != nil {
// Note: In case your wondering why we are not gzip encoding....
Expand Down

0 comments on commit a9d2090

Please sign in to comment.