mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-09-22 08:00:53 +00:00
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:
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user