-
Notifications
You must be signed in to change notification settings - Fork 2
/
web.go
51 lines (41 loc) · 977 Bytes
/
web.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
46
47
48
49
50
51
package steamuser
import (
"net/http"
"net/http/cookiejar"
"net/url"
"github.com/vincentserpoul/mangosteam"
)
// NewWebSteamClient creates a web steam client with the right cookies
// to interact with web steam
func (user *User) NewWebSteamClient() *http.Client {
client := &http.Client{}
client.Jar, _ = cookiejar.New(nil)
steamURL, _ := url.Parse(mangosteam.BaseSteamWebURL)
var cookiesToBeSet []*http.Cookie
if user.SteamLogin != "" {
cookiesToBeSet = append(cookiesToBeSet,
&http.Cookie{
Name: "steamLogin",
Value: user.SteamLogin,
},
)
}
if user.SteamLoginSecure != "" {
cookiesToBeSet = append(cookiesToBeSet,
&http.Cookie{
Name: "steamLoginSecure",
Value: user.SteamLoginSecure,
},
)
}
if user.LastSessionID != "" {
cookiesToBeSet = append(cookiesToBeSet,
&http.Cookie{
Name: "sessionid",
Value: user.LastSessionID,
},
)
}
client.Jar.SetCookies(steamURL, cookiesToBeSet)
return client
}