Skip to content

Commit

Permalink
SetFronted before api call.
Browse files Browse the repository at this point in the history
  • Loading branch information
jigar-f committed Dec 10, 2024
1 parent 28a64f4 commit 14758b5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,6 @@ set-version:
NEXT_BUILD=$$(($$CURRENT_BUILD + 1)); \
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $$NEXT_BUILD" $(INFO_PLIST)

ios: macos build-framework ffigen

ios-release: set-version guard-SENTRY_AUTH_TOKEN guard-SENTRY_ORG guard-SENTRY_PROJECT_IOS pubget
@echo "Flutter Clean"
flutter clean
Expand Down
33 changes: 33 additions & 0 deletions internalsdk/pro/pro.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@ import (
"encoding/json"
"fmt"
"net/http"
"path/filepath"
"strings"
"sync"
"time"

"github.com/getlantern/errors"
"github.com/getlantern/flashlight/v7/config"
"github.com/getlantern/flashlight/v7/proxied"
"github.com/getlantern/fronted"
"github.com/getlantern/golog"
"github.com/getlantern/lantern-client/internalsdk/common"
"github.com/getlantern/lantern-client/internalsdk/protos"
"github.com/getlantern/lantern-client/internalsdk/webclient"
"github.com/go-resty/resty/v2"

"github.com/leekchan/accounting"
tls "github.com/refraction-networking/utls"
"github.com/shopspring/decimal"
"google.golang.org/protobuf/encoding/protojson"
)
Expand Down Expand Up @@ -88,6 +92,35 @@ func NewClient(baseURL string, userConfig func() common.UserConfig) ProClient {
}
}

func NewIOSClient(baseURL string, userConfig func() common.UserConfig, configPath string) ProClient {
fronted, err := fronted.NewFronted(filepath.Join(configPath, "masquerade_cache"), tls.HelloChrome_102, config.DefaultFrontedProviderID)
if err != nil {
log.Errorf("Unable to configure fronted: %v", err)
}
proxied.SetFronted(fronted)
log.Debugf("Using fronted: %v", fronted)

httpClient := &http.Client{
Transport: proxied.ParallelForIdempotent(),
Timeout: 30 * time.Second,
}

return &proClient{
userConfig: userConfig,
backoffRunner: &backoffRunner{},
RESTClient: webclient.NewRESTClient(&webclient.Opts{
// The default http.RoundTripper used by the ProClient is ParallelForIdempotent which
// attempts to send requests through both chained and direct fronted routes in parallel
// for HEAD and GET requests and ChainedThenFronted for all others.
HttpClient: httpClient,
OnBeforeRequest: func(client *resty.Client, req *http.Request) error {
prepareProRequest(req, common.ProAPIHost, userConfig())
return nil
},
}),
}
}

// prepareProRequest normalizes requests to the pro server with device ID, user ID, etc set.
func prepareProRequest(r *http.Request, proAPIHost string, userConfig common.UserConfig) {
if r.URL.Scheme == "" {
Expand Down
18 changes: 16 additions & 2 deletions internalsdk/session_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,25 @@ func NewSessionModel(mdb minisql.DB, opts *SessionModelOpts) (*SessionModel, err
token, _ := m.GetToken()
lang, _ := m.Locale()

m.proClient = createProClient(m, opts.Platform)

authUrl := common.DFBaseUrl
if opts.Platform == "ios" {
authUrl = common.APIBaseUrl
m.proClient = pro.NewIOSClient(fmt.Sprintf("https://%s", common.ProAPIHost), func() common.UserConfig {
internalHeaders := map[string]string{
common.PlatformHeader: opts.Platform,
common.AppVersionHeader: common.ApplicationVersion,
}
return common.NewUserConfig(
common.DefaultAppName,
deviceID,
userID,
token,
internalHeaders,
lang,
)
}, opts.ConfigPath)
} else {
m.proClient = createProClient(m, opts.Platform)
}
m.authClient = auth.NewClient(fmt.Sprintf("https://%s", authUrl), func() common.UserConfig {
internalHeaders := map[string]string{
Expand Down

0 comments on commit 14758b5

Please sign in to comment.