Replace websocket flow with SSE support in backend.
Update handlers, services, router, and data conversion logic to support server-sent events and related message pipeline changes. Made-with: Cursor
This commit is contained in:
@@ -1,18 +1,10 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
// CORS CORS中间件
|
||||
func CORS() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
// 获取请求路径
|
||||
path := c.Request.URL.Path
|
||||
|
||||
c.Header("Access-Control-Allow-Origin", "*")
|
||||
c.Header("Access-Control-Allow-Methods", "GET, POST, PUT, PATCH, DELETE, OPTIONS")
|
||||
// 添加 WebSocket 升级所需的头
|
||||
@@ -22,25 +14,10 @@ func CORS() gin.HandlerFunc {
|
||||
|
||||
// 处理 WebSocket 升级请求的预检
|
||||
if c.Request.Method == "OPTIONS" {
|
||||
log.Printf("[CORS] OPTIONS 预检请求: %s", path)
|
||||
c.AbortWithStatus(204)
|
||||
return
|
||||
}
|
||||
|
||||
// 针对 WebSocket 路径的特殊处理
|
||||
if path == "/ws" {
|
||||
connection := c.GetHeader("Connection")
|
||||
upgrade := c.GetHeader("Upgrade")
|
||||
log.Printf("[CORS] WebSocket 请求: Connection=%s, Upgrade=%s", connection, upgrade)
|
||||
|
||||
// 检查是否是有效的 WebSocket 升级请求
|
||||
if strings.Contains(strings.ToLower(connection), "upgrade") && strings.ToLower(upgrade) == "websocket" {
|
||||
log.Printf("[CORS] 有效的 WebSocket 升级请求")
|
||||
} else {
|
||||
log.Printf("[CORS] 警告: 不是有效的 WebSocket 升级请求!")
|
||||
}
|
||||
}
|
||||
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user