2023-08-13 16:19:23 -04:00
|
|
|
package windscribe
|
|
|
|
|
|
|
|
import (
|
2023-08-13 23:22:48 -04:00
|
|
|
"context"
|
2023-08-13 16:19:23 -04:00
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
"net/http/cookiejar"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
ReadLimit int64 = 128 * 1024
|
|
|
|
)
|
|
|
|
|
|
|
|
type Client interface {
|
2023-08-13 23:22:48 -04:00
|
|
|
Auth(context.Context, Auth) error
|
|
|
|
MatchingPort(context.Context) error
|
2023-08-13 16:19:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type client struct {
|
2023-08-13 23:22:48 -04:00
|
|
|
hc *http.Client
|
2023-08-13 16:19:23 -04:00
|
|
|
auth Auth
|
2023-08-13 23:22:48 -04:00
|
|
|
csrf *CSRF
|
2023-08-13 16:19:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func New() Client {
|
|
|
|
jar, err := cookiejar.New(nil)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
c := &client{
|
|
|
|
hc: &http.Client{
|
|
|
|
Jar: jar,
|
|
|
|
Transport: &http.Transport{
|
|
|
|
Proxy: http.ProxyFromEnvironment,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
|
|
|
func fillReq(r *http.Request) {
|
|
|
|
r.Header.Set("Connection", "keep-alive")
|
|
|
|
|
|
|
|
hdr := map[string]string{
|
2023-08-13 23:22:48 -04:00
|
|
|
"cache-control": `max-age=0`,
|
|
|
|
"sec-ch-ua": `"Not/A)Brand";v="99", "Google Chrome";v="115", "Chromium";v="115"`,
|
|
|
|
"sec-ch-ua-mobile": `?0`,
|
|
|
|
"sec-ch-ua-platform": `"macOS"`,
|
|
|
|
"origin": `https://windscribe.com`,
|
|
|
|
"dnt": `1`,
|
2023-08-13 16:19:23 -04:00
|
|
|
"upgrade-insecure-requests": `1`,
|
2023-08-13 23:22:48 -04:00
|
|
|
"content-type": `application/x-www-form-urlencoded`,
|
|
|
|
"user-agent": `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36`,
|
|
|
|
"accept": `text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7`,
|
|
|
|
"sec-fetch-site": `same-origin`,
|
|
|
|
"sec-fetch-mode": `navigate`,
|
|
|
|
"sec-fetch-user": `?1`,
|
|
|
|
"sec-fetch-dest": `document`,
|
|
|
|
"referer": `https://windscribe.com/login`,
|
|
|
|
"accept-language": `en-US,en;q=0.9,fr;q=0.8`,
|
|
|
|
"sec-gpc": `1`,
|
2023-08-13 16:19:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
for k, v := range hdr {
|
|
|
|
r.Header.Set(k, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func cleanupBody(body io.ReadCloser) {
|
|
|
|
io.Copy(io.Discard, &io.LimitedReader{
|
|
|
|
R: body,
|
|
|
|
N: ReadLimit,
|
|
|
|
})
|
|
|
|
body.Close()
|
|
|
|
}
|