mirror of
https://github.com/gospider007/requests.git
synced 2025-12-24 13:57:52 +08:00
optimize cookies
This commit is contained in:
70
tools.go
70
tools.go
@@ -14,47 +14,21 @@ import (
|
||||
"golang.org/x/net/http/httpguts"
|
||||
)
|
||||
|
||||
func cloneUrl(u *url.URL) *url.URL {
|
||||
r := *u
|
||||
return &r
|
||||
}
|
||||
func ParseIp(ip net.IP) AddrType {
|
||||
if ip != nil {
|
||||
if ip4 := ip.To4(); ip4 != nil {
|
||||
return 4
|
||||
} else if ip6 := ip.To16(); ip6 != nil {
|
||||
return 6
|
||||
func getHost(req *http.Request) string {
|
||||
host := req.Host
|
||||
if host == "" {
|
||||
host = req.URL.Host
|
||||
}
|
||||
_, port, _ := net.SplitHostPort(host)
|
||||
if port == "" {
|
||||
if req.URL.Scheme == "https" {
|
||||
port = "443"
|
||||
} else {
|
||||
port = "80"
|
||||
}
|
||||
return fmt.Sprintf("%s:%s", host, port)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
func GetHost(addrTypes ...AddrType) net.IP {
|
||||
hosts := GetHosts(addrTypes...)
|
||||
if len(hosts) == 0 {
|
||||
return nil
|
||||
} else {
|
||||
return hosts[0]
|
||||
}
|
||||
}
|
||||
func GetHosts(addrTypes ...AddrType) []net.IP {
|
||||
var addrType AddrType
|
||||
if len(addrTypes) > 0 {
|
||||
addrType = addrTypes[0]
|
||||
}
|
||||
result := []net.IP{}
|
||||
lls, err := net.InterfaceAddrs()
|
||||
if err != nil {
|
||||
return result
|
||||
}
|
||||
for _, ll := range lls {
|
||||
mm, ok := ll.(*net.IPNet)
|
||||
if ok && mm.IP.IsPrivate() {
|
||||
if addrType == 0 || ParseIp(mm.IP) == addrType {
|
||||
result = append(result, mm.IP)
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
return host
|
||||
}
|
||||
func getAddr(uurl *url.URL) string {
|
||||
if uurl == nil {
|
||||
@@ -71,21 +45,9 @@ func getAddr(uurl *url.URL) string {
|
||||
}
|
||||
return uurl.Host
|
||||
}
|
||||
func getHost(req *http.Request) string {
|
||||
host := req.Host
|
||||
if host == "" {
|
||||
host = req.URL.Host
|
||||
}
|
||||
_, port, _ := net.SplitHostPort(host)
|
||||
if port == "" {
|
||||
if req.URL.Scheme == "https" {
|
||||
port = "443"
|
||||
} else {
|
||||
port = "80"
|
||||
}
|
||||
return fmt.Sprintf("%s:%s", host, port)
|
||||
}
|
||||
return host
|
||||
func cloneUrl(u *url.URL) *url.URL {
|
||||
r := *u
|
||||
return &r
|
||||
}
|
||||
|
||||
var replaceMap = map[string]string{
|
||||
|
||||
Reference in New Issue
Block a user