Skip to content

Commit

Permalink
clean-up auth client request middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
atavism committed Jun 18, 2024
1 parent 7361dac commit 5d5bd10
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions internalsdk/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package auth
import (
"context"
"net/http"
"strconv"
"strings"

"github.com/getlantern/golog"
Expand Down Expand Up @@ -52,22 +51,15 @@ func NewClient(baseURL string, opts *webclient.Opts) AuthClient {
if httpClient == nil {
httpClient = &http.Client{}
}
webclient := webclient.NewRESTClient(defaultwebclient.SendToURL(httpClient, baseURL, func(client *resty.Client, req *resty.Request) error {
req.SetHeader(common.ContentType, "application/x-protobuf")
headers := map[string]string{}
webclient := webclient.NewRESTClient(defaultwebclient.SendToURL(httpClient, baseURL, func(client *resty.Client, restyReq *resty.Request) error {
restyReq.SetHeader(common.ContentType, "application/x-protobuf")
uc := opts.UserConfig()
if req.URL != "" && strings.HasPrefix(req.URL, "/users/#") {
if restyReq.URL != "" && strings.HasPrefix(restyReq.URL, "/users/#") {
// for the /users/# endpoint, we do need to pass all default headers
headers[common.DeviceIdHeader] = uc.GetDeviceID()
headers[common.UserIdHeader] = strconv.FormatInt(uc.GetUserID(), 10)
headers[common.ProTokenHeader] = uc.GetToken()
req := restyReq.RawRequest
common.AddCommonUserHeaders(uc, req)
common.AddInternalHeaders(uc, req)
}

// Import all the internal headers
for k, v := range uc.GetInternalHeaders() {
headers[k] = v
}
req.SetHeaders(headers)
return nil
}, nil))

Expand Down

0 comments on commit 5d5bd10

Please # to comment.