Skip to content

Commit

Permalink
Merge pull request #110 from Snawoot/cust_user_agent
Browse files Browse the repository at this point in the history
Customizable User-Agent
  • Loading branch information
Snawoot authored Dec 1, 2023
2 parents 47721e8 + 54fa9a4 commit 2ff8391
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ zagent248.hola.org,165.22.65.3,22222,22223,22224,22225,22226,digitalocean
| resolver | String | DNS/DoH/DoT resolver to workaround Hola blocked hosts. See https://github.com/ameshkov/dnslookup/ for upstream DNS URL format. (default "https://cloudflare-dns.com/dns-query") |
| rotate | Duration | rotate user ID once per given period (default 1h0m0s) |
| timeout | Duration | timeout for network operations (default 35s) |
| user-agent | String | value of User-Agent header in requests (default "Mozilla/5.0 (X11; Linux x86\_64; rv:109.0) Gecko/20100101 Firefox/118.0") |
| verbosity | Number | logging verbosity (10 - debug, 20 - info, 30 - warning, 40 - error, 50 - critical) (default 20) |

## See also
Expand Down
13 changes: 11 additions & 2 deletions holaapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/google/uuid"
)

const USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36"
const EXT_BROWSER = "chrome"
const PRODUCT = "cws"
const CCGI_URL = "https://client.hola.org/client_cgi/"
Expand All @@ -41,6 +40,16 @@ var TemporaryBanError = errors.New("temporary ban detected")
var PermanentBanError = errors.New("permanent ban detected")
var EmptyResponseError = errors.New("empty response")

var userAgent = "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/118.0"

func SetUserAgent(ua string) {
userAgent = ua
}

func GetUserAgent() string {
return userAgent
}

type CountryList []string

type BgInitResponse struct {
Expand Down Expand Up @@ -158,7 +167,7 @@ func do_req(ctx context.Context, client *http.Client, method, url string, query,
if query != nil {
req.URL.RawQuery = query.Encode()
}
req.Header.Set("User-Agent", USER_AGENT)
req.Header.Set("User-Agent", userAgent)
resp, err := client.Do(req)
if err != nil {
return nil, err
Expand Down
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type CLIArgs struct {
backoffInitial time.Duration
backoffDeadline time.Duration
hideSNI bool
userAgent string
}

func parse_args() CLIArgs {
Expand Down Expand Up @@ -94,6 +95,7 @@ func parse_args() CLIArgs {
"Format: <http|https|socks5|socks5h>://[login:password@]host[:port] "+
"Examples: http://user:password@192.168.1.1:3128, socks5://10.0.0.1:1080")
flag.StringVar(&args.caFile, "cafile", "", "use custom CA certificate bundle file")
flag.StringVar(&args.userAgent, "user-agent", GetUserAgent(), "value of User-Agent header in requests")
flag.BoolVar(&args.hideSNI, "hide-SNI", true, "hide SNI in TLS sessions with proxy server")
flag.Parse()
if args.country == "" {
Expand Down Expand Up @@ -176,6 +178,8 @@ func run() int {
UpdateHolaDialer(dialer)
}

SetUserAgent(args.userAgent)

if args.list_countries {
return print_countries(args.timeout)
}
Expand Down

0 comments on commit 2ff8391

Please sign in to comment.