mirror of
https://github.com/Snawoot/windscribe-proxy.git
synced 2026-04-07 04:08:17 +00:00
wndclient: WIP
This commit is contained in:
@@ -1,5 +1,16 @@
|
||||
package wndclient
|
||||
|
||||
import (
|
||||
//"context"
|
||||
//"encoding/json"
|
||||
//"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sync"
|
||||
)
|
||||
|
||||
const (
|
||||
READ_LIMIT int64 = 128 * 1024
|
||||
SESSION_TYPE_WEB = 1
|
||||
@@ -26,21 +37,23 @@ var DefaultWndEndpoints = WndEndpoints{
|
||||
}
|
||||
|
||||
type WndSettings struct {
|
||||
Platform string
|
||||
Type string
|
||||
UserAgent string
|
||||
Origin string
|
||||
SessionType int
|
||||
Endpoints WndEndpoints
|
||||
ClientAuthSecret string
|
||||
Platform string
|
||||
Type string
|
||||
UserAgent string
|
||||
Origin string
|
||||
SessionType int
|
||||
Endpoints WndEndpoints
|
||||
}
|
||||
|
||||
var DefaultWndSettings = WndSettings{
|
||||
Platform: "chrome",
|
||||
Type: "chrome",
|
||||
UserAgent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36",
|
||||
Origin: "chrome-extension://hnmpcagpplmpfojmgmnngilcnanddlhb",
|
||||
SessionType: SESSION_TYPE_EXT,
|
||||
Endpoints: DefaultWndEndpoints,
|
||||
ClientAuthSecret: "952b4412f002315aa50751032fcaab03",
|
||||
Platform: "chrome",
|
||||
Type: "chrome",
|
||||
UserAgent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36",
|
||||
Origin: "chrome-extension://hnmpcagpplmpfojmgmnngilcnanddlhb",
|
||||
SessionType: SESSION_TYPE_EXT,
|
||||
Endpoints: DefaultWndEndpoints,
|
||||
}
|
||||
|
||||
type WndClient struct {
|
||||
@@ -56,4 +69,46 @@ type WndClient struct {
|
||||
Status int
|
||||
UserID string
|
||||
SessionAuthHash string
|
||||
Mux sync.Mutex
|
||||
}
|
||||
|
||||
type StrKV map[string]string
|
||||
|
||||
func NewWndClient(transport http.RoundTripper) (*WndClient, error) {
|
||||
if transport == nil {
|
||||
transport = http.DefaultTransport
|
||||
}
|
||||
|
||||
jar, err := NewStdJar()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &SEClient{
|
||||
httpClient: &http.Client{
|
||||
Jar: jar,
|
||||
Transport: transport,
|
||||
},
|
||||
Settings: DefaultWndSettings,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *SEClient) ResetCookies() error {
|
||||
c.Mux.Lock()
|
||||
defer c.Mux.Unlock()
|
||||
return c.resetCookies()
|
||||
}
|
||||
|
||||
func (c *SEClient) resetCookies() error {
|
||||
return (c.httpClient.Jar.(*StdJar)).Reset()
|
||||
}
|
||||
|
||||
// Does cleanup of HTTP response in order to make it reusable by keep-alive
|
||||
// logic of HTTP client
|
||||
func cleanupBody(body io.ReadCloser) {
|
||||
io.Copy(ioutil.Discard, &io.LimitedReader{
|
||||
R: body,
|
||||
N: READ_LIMIT,
|
||||
})
|
||||
body.Close()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user