mirror of
https://github.com/qdm12/gluetun.git
synced 2026-08-05 03:43:24 +02:00
fix(ipvanish): updater user agent to work again
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/common"
|
||||
"github.com/qdm12/gluetun/internal/updater/openvpn"
|
||||
"github.com/qdm12/gluetun/internal/updater/unzip"
|
||||
"golang.org/x/text/cases"
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
@@ -17,6 +18,8 @@ func (u *Updater) FetchServers(ctx context.Context, minServers int) (
|
||||
servers []models.Server, err error,
|
||||
) {
|
||||
const url = "https://configs.ipvanish.com/openvpn/v2.6.0-0/configs.zip"
|
||||
//nolint:lll
|
||||
ctx = unzip.WithUserAgent(ctx, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36")
|
||||
contents, err := u.unzipper.FetchAndExtract(ctx, url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -195,12 +195,13 @@ func Test_Updater_GetServers(t *testing.T) {
|
||||
|
||||
unzipper := common.NewMockUnzipper(ctrl)
|
||||
const zipURL = "https://configs.ipvanish.com/openvpn/v2.6.0-0/configs.zip"
|
||||
unzipper.EXPECT().FetchAndExtract(ctx, zipURL).
|
||||
// Context is wrapped with User-Agent for ipvanish, so use Any() for the ctx arg
|
||||
unzipper.EXPECT().FetchAndExtract(gomock.Any(), zipURL). //nolint:dogsled
|
||||
Return(testCase.unzipContents, testCase.unzipErr)
|
||||
|
||||
parallelResolver := common.NewMockParallelResolver(ctrl)
|
||||
if testCase.expectResolve {
|
||||
parallelResolver.EXPECT().Resolve(ctx, testCase.resolverSettings).
|
||||
parallelResolver.EXPECT().Resolve(gomock.Any(), testCase.resolverSettings). //nolint:dogsled
|
||||
Return(testCase.hostToIPs, testCase.resolveWarnings, testCase.resolveErr)
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,11 @@ func (u *Unzipper) FetchAndExtract(ctx context.Context, url string) (
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
request.Header.Set("User-Agent", "gluetun")
|
||||
if userAgent, ok := ctx.Value(userAgentContextKey).(string); ok && userAgent != "" {
|
||||
request.Header.Set("User-Agent", userAgent)
|
||||
} else {
|
||||
request.Header.Set("User-Agent", "gluetun")
|
||||
}
|
||||
|
||||
response, err := u.client.Do(request)
|
||||
if err != nil {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package unzip
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
@@ -8,6 +9,16 @@ type Unzipper struct {
|
||||
client *http.Client
|
||||
}
|
||||
|
||||
type contextKey int
|
||||
|
||||
const (
|
||||
userAgentContextKey contextKey = iota
|
||||
)
|
||||
|
||||
func WithUserAgent(ctx context.Context, userAgent string) context.Context {
|
||||
return context.WithValue(ctx, userAgentContextKey, userAgent)
|
||||
}
|
||||
|
||||
func New(client *http.Client) *Unzipper {
|
||||
return &Unzipper{
|
||||
client: client,
|
||||
|
||||
Reference in New Issue
Block a user