forked from neucn/neugo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession_linux.go
More file actions
36 lines (32 loc) · 737 Bytes
/
session_linux.go
File metadata and controls
36 lines (32 loc) · 737 Bytes
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
//go:build linux
package neugo
import (
"net"
"net/http"
"net/http/cookiejar"
"syscall"
"time"
)
// NewSession returns a *http.Client with an empty cookie jar ,timeout of 6s and transport with specific fwmark.
func NewFwmarkSession(mark uint32) *http.Client {
dialer := &net.Dialer{
Control: func(network, address string, c syscall.RawConn) error {
return c.Control(func(fd uintptr) {
err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_MARK, int(mark))
if err != nil {
return
}
})
},
}
tr := &http.Transport{
DialContext: dialer.DialContext,
}
jar, _ := cookiejar.New(nil)
n := &http.Client{
Timeout: 6 * time.Second,
Jar: jar,
Transport: tr,
}
return n
}