更新 proxy/handler.go

This commit is contained in:
XOF
2025-12-15 19:47:50 +08:00
parent 6267509fa4
commit 576f7989f6

View File

@@ -63,10 +63,25 @@ func (h *ProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
session := h.sessionManager.Get(token)
if session == nil {
http.Error(w, "Session expired or invalid", http.StatusUnauthorized)
return
// 尝试从 cookie 恢复
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
}
}
// 设置 cookie10分钟有效期
http.SetCookie(w, &http.Cookie{
Name: "ORIGINALHOST_" + token,
Value: session.TargetURL,
Path: "/p/" + token,
MaxAge: 600,
HttpOnly: true,
SameSite: http.SameSiteLaxMode,
})
var targetURL string
if strings.HasPrefix(targetPath, "http:/") && !strings.HasPrefix(targetPath, "http://") {