feat: Implement connection closure handling in status 444 (#11574)

* feat: Implement connection closure handling in security module

* refactor: Rename closeConn to CloseDirectly for clarity in security module
This commit is contained in:
KOMATA
2026-01-06 16:41:20 +08:00
committed by GitHub
parent 6c51b31270
commit f67bdf0c22
+22 -5
View File
@@ -3,6 +3,11 @@ package security
import (
"encoding/base64"
"fmt"
"net/http"
"regexp"
"strconv"
"strings"
"github.com/1Panel-dev/1Panel/core/app/repo"
"github.com/1Panel-dev/1Panel/core/app/service"
"github.com/1Panel-dev/1Panel/core/cmd/server/res"
@@ -11,10 +16,6 @@ import (
"github.com/1Panel-dev/1Panel/core/global"
"github.com/1Panel-dev/1Panel/core/utils/common"
"github.com/gin-gonic/gin"
"net/http"
"regexp"
"strconv"
"strings"
)
func HandleNotRoute(c *gin.Context) bool {
@@ -98,7 +99,7 @@ func HandleNotSecurity(c *gin.Context, resType string) {
return
}
if resPage == "444" {
c.String(444, "")
CloseDirectly(c)
return
}
@@ -183,3 +184,19 @@ func checkSession(c *gin.Context) bool {
_, err := global.SESSION.Get(c)
return err == nil
}
func CloseDirectly(c *gin.Context) {
hijacker, ok := c.Writer.(http.Hijacker)
if !ok {
c.AbortWithStatus(http.StatusForbidden)
return
}
conn, _, err := hijacker.Hijack()
if err != nil {
c.AbortWithStatus(http.StatusForbidden)
return
}
conn.Close()
c.Abort()
}