Skip to content

Commit 649237a

Browse files
committed
Merge branch 'pld'
2 parents 278721e + 1850cf9 commit 649237a

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

internal/reverse/response.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,16 @@ func (reverse *Reverse) modifyLocationHeader(shost string, response *http.Respon
149149
log.Trace("Location: %s", location.String())
150150
target := reverse.AllowSite[shost]
151151
targetHost, _ := url.Parse(target)
152+
locationHost, err := utils.Parse(location.String())
153+
if err != nil {
154+
return err
155+
}
152156

153-
if targetHost.Host == location.Host {
157+
if targetHost.Host == locationHost.Host {
154158
location.Scheme = ""
155159
location.Host = ""
160+
} else {
161+
log.Trace("url: %s,Location: %s", response.Request.URL, location.String())
156162
}
157163
if location.String() == "" {
158164
log.Trace("url: %s,Location is empty", response.Request.URL)
@@ -171,7 +177,7 @@ func (reverse *Reverse) modifyCookieHeader(shost string, response *http.Response
171177
var mcook []string
172178
addr, _, err := utils.SplitHost(shost)
173179
if err != nil {
174-
return err
180+
addr = shost
175181
}
176182
for _, value := range rcookies {
177183
// 关闭 Secure

internal/reverse/utils.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"net/http"
66
"net/http/httputil"
7+
"strings"
78

89
"goblin/pkg/utils"
910
)
@@ -25,3 +26,23 @@ func dumpReq(r *http.Request) string {
2526
req, _ := httputil.DumpRequest(r, true)
2627
return fmt.Sprintf(info, r.URL.RequestURI(), GetClientIP(r), string(req), r.URL.RequestURI())
2728
}
29+
30+
// IsWebSocketRequest returns a boolean indicating whether the request has the
31+
func IsWebSocketRequest(r *http.Request) bool {
32+
contains := func(key, val string) bool {
33+
vv := strings.Split(r.Header.Get(key), ",")
34+
for _, v := range vv {
35+
if val == strings.ToLower(strings.TrimSpace(v)) {
36+
return true
37+
}
38+
}
39+
return false
40+
}
41+
if !contains("Connection", "upgrade") {
42+
return false
43+
}
44+
if !contains("Upgrade", "websocket") {
45+
return false
46+
}
47+
return true
48+
}

0 commit comments

Comments
 (0)