From 91fd2f3f61276227a1ae138a6b2304309d8eeca6 Mon Sep 17 00:00:00 2001 From: Marcus Goldschmidt Date: Fri, 20 Dec 2024 15:18:36 -0400 Subject: [PATCH] Add uhttp.WithBearerToken method --- pkg/uhttp/wrapper.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/uhttp/wrapper.go b/pkg/uhttp/wrapper.go index d9f78db5..5396e4f2 100644 --- a/pkg/uhttp/wrapper.go +++ b/pkg/uhttp/wrapper.go @@ -30,6 +30,7 @@ const ( applicationFormUrlencoded = "application/x-www-form-urlencoded" applicationVndApiJSON = "application/vnd.api+json" acceptHeader = "Accept" + authorizationHeader = "Authorization" ) const maxBodySize = 4096 @@ -464,6 +465,10 @@ func WithAccept(value string) RequestOption { return WithHeader(acceptHeader, value) } +func WithBearerToken(token string) RequestOption { + return WithHeader(authorizationHeader, fmt.Sprintf("Bearer %s", token)) +} + func (c *BaseHttpClient) NewRequest(ctx context.Context, method string, url *url.URL, options ...RequestOption) (*http.Request, error) { var buffer io.ReadWriter var headers map[string]string = make(map[string]string)