更新 proxy/handler.go
This commit is contained in:
@@ -63,10 +63,25 @@ func (h *ProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
session := h.sessionManager.Get(token)
|
session := h.sessionManager.Get(token)
|
||||||
if session == nil {
|
if session == nil {
|
||||||
http.Error(w, "Session expired or invalid", http.StatusUnauthorized)
|
// 尝试从 cookie 恢复
|
||||||
return
|
if cookie, err := r.Cookie("ORIGINALHOST_" + token); err == nil {
|
||||||
|
session = &ProxySession{TargetURL: cookie.Value}
|
||||||
|
} else {
|
||||||
|
http.Error(w, "Session expired or invalid", http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 设置 cookie(10分钟有效期)
|
||||||
|
http.SetCookie(w, &http.Cookie{
|
||||||
|
Name: "ORIGINALHOST_" + token,
|
||||||
|
Value: session.TargetURL,
|
||||||
|
Path: "/p/" + token,
|
||||||
|
MaxAge: 600,
|
||||||
|
HttpOnly: true,
|
||||||
|
SameSite: http.SameSiteLaxMode,
|
||||||
|
})
|
||||||
|
|
||||||
var targetURL string
|
var targetURL string
|
||||||
|
|
||||||
if strings.HasPrefix(targetPath, "http:/") && !strings.HasPrefix(targetPath, "http://") {
|
if strings.HasPrefix(targetPath, "http:/") && !strings.HasPrefix(targetPath, "http://") {
|
||||||
|
|||||||
Reference in New Issue
Block a user