feat(http): add Chromium client hints
This commit is contained in:
parent
75bf1169ba
commit
19bbde3b2c
4 changed files with 35 additions and 2 deletions
|
|
@ -23,6 +23,10 @@ func Headers() stdHttp.Header {
|
|||
headers.Set("Sec-Fetch-Mode", "cors")
|
||||
headers.Set("Sec-Fetch-Site", "same-origin")
|
||||
|
||||
headers.Set("Sec-Ch-Ua", BrowserBrands())
|
||||
headers.Set("Sec-Ch-Ua-Mobile", "?0")
|
||||
headers.Set("Sec-Ch-Ua-Platform", `"`+OS+`"`)
|
||||
|
||||
headers.Set("X-Debug-Options", "bugReporterEnabled")
|
||||
headers.Set("X-Discord-Locale", string(Locale))
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,11 @@ func BrowserUserAgent() string {
|
|||
return "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " + tls.BrowserName() + "/" + tls.BrowserVersion() + " Safari/537.36"
|
||||
}
|
||||
|
||||
func BrowserBrands() string {
|
||||
version := tls.BrowserMajorVersion()
|
||||
return `"Chromium";v="` + version + `", "Not-A.Brand";v="24", "Google ` + tls.BrowserName() + `";v="` + version + `"`
|
||||
}
|
||||
|
||||
func CommonProperties() gateway.IdentifyProperties {
|
||||
return gateway.IdentifyProperties{
|
||||
gateway.IdentifyDevice: "",
|
||||
|
|
|
|||
|
|
@ -33,3 +33,23 @@ func TestBrowserIdentity(t *testing.T) {
|
|||
t.Fatalf("user agent does not contain %q", product)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBrowserClientHints(t *testing.T) {
|
||||
headers := Headers()
|
||||
tests := []struct {
|
||||
name string
|
||||
want string
|
||||
}{
|
||||
{"Sec-Ch-Ua", `"Chromium";v="146", "Not-A.Brand";v="24", "Google Chrome";v="146"`},
|
||||
{"Sec-Ch-Ua-Mobile", "?0"},
|
||||
{"Sec-Ch-Ua-Platform", `"Windows"`},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
if got := headers.Get(test.name); got != test.want {
|
||||
t.Fatalf("got = %q, want = %q", got, test.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,10 @@ func BrowserName() string {
|
|||
return clientProfile.GetClientHelloId().Client
|
||||
}
|
||||
|
||||
func BrowserVersion() string {
|
||||
return clientProfile.GetClientHelloId().Version + ".0.0.0"
|
||||
func BrowserMajorVersion() string {
|
||||
return clientProfile.GetClientHelloId().Version
|
||||
}
|
||||
|
||||
func BrowserVersion() string {
|
||||
return BrowserMajorVersion() + ".0.0.0"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue