-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
45 lines (39 loc) · 842 Bytes
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package gopyload
import (
"net/http"
"net/http/cookiejar"
)
type client struct {
http.Client
headers headersMap
ourCookie http.CookieJar
}
func NewClient() *client {
jar, _ := cookiejar.New(nil)
return &client{
headers: defaultPyloadHeaders,
ourCookie: jar,
Client: http.Client{
Jar: jar,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return nil
},
},
}
}
func (c *client) Get(url string) (resp *http.Response, err error) {
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
}
addMapToHeaders(req, c.headers)
return c.Client.Do(req)
}
func (c *client) Post(url string) (resp *http.Response, err error) {
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
}
addMapToHeaders(req, c.headers)
return c.Client.Do(req)
}