-
Notifications
You must be signed in to change notification settings - Fork 160
/
surf.go
45 lines (37 loc) · 1.36 KB
/
surf.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 surf ensembles other packages into a usable browser.
package surf
import (
"github.com/headzoo/surf/agent"
"github.com/headzoo/surf/browser"
"github.com/headzoo/surf/jar"
)
var (
// DefaultUserAgent is the global user agent value.
DefaultUserAgent = agent.Create()
// DefaultSendReferer is the global value for the AttributeSendReferer attribute.
DefaultSendReferer = true
// DefaultMetaRefreshHandling is the global value for the AttributeHandleRefresh attribute.
DefaultMetaRefreshHandling = true
// DefaultFollowRedirects is the global value for the AttributeFollowRedirects attribute.
DefaultFollowRedirects = true
// DefaultMaxHistoryLength is the global value for max history length.
DefaultMaxHistoryLength = 0
)
// NewBrowser creates and returns a *browser.Browser type.
func NewBrowser() *browser.Browser {
bow := &browser.Browser{}
bow.SetUserAgent(DefaultUserAgent)
bow.SetState(&jar.State{})
bow.SetCookieJar(jar.NewMemoryCookies())
bow.SetBookmarksJar(jar.NewMemoryBookmarks())
hist := jar.NewMemoryHistory()
hist.SetMax(DefaultMaxHistoryLength)
bow.SetHistoryJar(hist)
bow.SetHeadersJar(jar.NewMemoryHeaders())
bow.SetAttributes(browser.AttributeMap{
browser.SendReferer: DefaultSendReferer,
browser.MetaRefreshHandling: DefaultMetaRefreshHandling,
browser.FollowRedirects: DefaultFollowRedirects,
})
return bow
}