Skip to content

Commit

Permalink
Merge branch 'pld'
Browse files Browse the repository at this point in the history
  • Loading branch information
Becivells committed Sep 18, 2021
2 parents 278721e + 1850cf9 commit 649237a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
10 changes: 8 additions & 2 deletions internal/reverse/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,16 @@ func (reverse *Reverse) modifyLocationHeader(shost string, response *http.Respon
log.Trace("Location: %s", location.String())
target := reverse.AllowSite[shost]
targetHost, _ := url.Parse(target)
locationHost, err := utils.Parse(location.String())
if err != nil {
return err
}

if targetHost.Host == location.Host {
if targetHost.Host == locationHost.Host {
location.Scheme = ""
location.Host = ""
} else {
log.Trace("url: %s,Location: %s", response.Request.URL, location.String())
}
if location.String() == "" {
log.Trace("url: %s,Location is empty", response.Request.URL)
Expand All @@ -171,7 +177,7 @@ func (reverse *Reverse) modifyCookieHeader(shost string, response *http.Response
var mcook []string
addr, _, err := utils.SplitHost(shost)
if err != nil {
return err
addr = shost
}
for _, value := range rcookies {
// 关闭 Secure
Expand Down
21 changes: 21 additions & 0 deletions internal/reverse/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net/http"
"net/http/httputil"
"strings"

"goblin/pkg/utils"
)
Expand All @@ -25,3 +26,23 @@ func dumpReq(r *http.Request) string {
req, _ := httputil.DumpRequest(r, true)
return fmt.Sprintf(info, r.URL.RequestURI(), GetClientIP(r), string(req), r.URL.RequestURI())
}

// IsWebSocketRequest returns a boolean indicating whether the request has the
func IsWebSocketRequest(r *http.Request) bool {
contains := func(key, val string) bool {
vv := strings.Split(r.Header.Get(key), ",")
for _, v := range vv {
if val == strings.ToLower(strings.TrimSpace(v)) {
return true
}
}
return false
}
if !contains("Connection", "upgrade") {
return false
}
if !contains("Upgrade", "websocket") {
return false
}
return true
}

0 comments on commit 649237a

Please sign in to comment.