Skip to content

Commit a9d2090

Browse files
handsomejack-42bgavrilMS
authored andcommitted
refactor(oauth): use constructor for new client in comm.HTTPClient.JSONCall
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.
1 parent fc5a751 commit a9d2090

File tree

1 file changed

+5
-6
lines changed
  • apps/internal/oauth/ops/internal/comm

1 file changed

+5
-6
lines changed

apps/internal/oauth/ops/internal/comm/comm.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ import (
1818
"strings"
1919
"time"
2020

21+
"github.com/google/uuid"
22+
2123
"github.com/AzureAD/microsoft-authentication-library-for-go/apps/errors"
2224
customJSON "github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/json"
2325
"github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/version"
24-
"github.com/google/uuid"
2526
)
2627

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

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

7979
addStdHeaders(headers)
80-
81-
req := &http.Request{Method: http.MethodGet, URL: u, Header: headers}
80+
req.Header = headers
8281

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

0 commit comments

Comments
 (0)