Skip to content

Commit

Permalink
解决请求头cookie读取bug
Browse files Browse the repository at this point in the history
  • Loading branch information
IFLYTEK\yuchen48 committed Oct 24, 2024
1 parent a0dcbda commit a82ecfd
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func main() {

dlSession := cfg.DlSession

fmt.Printf("ENV DL_SESSION: %s\n", cfg.DlSession)
// fmt.Printf("ENV DL_SESSION: %s\n", cfg.DlSession)

if tagHandling != "" && tagHandling != "html" && tagHandling != "xml" {
c.JSON(http.StatusBadRequest, gin.H{
Expand All @@ -178,15 +178,21 @@ func main() {
return
}

cookie := c.GetHeader("Cookie")
if cookie != "" {
dlSession = strings.Replace(cookie, "dl_session=", "", -1)
if cookie := c.GetHeader("Cookie"); cookie != "" {
for _, part := range strings.Split(cookie, ";") {
if strings.HasPrefix(part, "dl_session=") {
dlSession = strings.TrimPrefix(part, "dl_session=")
break
}
}
}

// log.Printf("dlSession: %s\n", dlSession)

if dlSession == "" {
c.JSON(http.StatusUnauthorized, gin.H{
"code": http.StatusUnauthorized,
"message": "No dl_session Found",
"message": "No dl_session Found.",
})
return
} else if strings.Contains(dlSession, ".") {
Expand Down

0 comments on commit a82ecfd

Please sign in to comment.