'SetCookie() couldn't set dot prefix for domain
package main
import (
"time"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
r.GET("/ping", func(c *gin.Context) {
c.SetCookie("NAME","VALUE",23*60,"/",".a.b.com",true,true)
c.JSON(200, gin.H{
"message": "pong",
})
})
r.Run(":8089") // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
time.Sleep(60*60)
}
then I executed ❯ curl -v GET 'http://0.0.0.0:8089/ping'
I hope it returned with
Set-Cookie: NAME=VALUE; Path=/; Domain=.a.b.com; Max-Age=1380; HttpOnly; Secure
The domain value with a dot prefix.
But it actually returned:
Set-Cookie: NAME=VALUE; Path=/; Domain=a.b.com; Max-Age=1380; HttpOnly; Secure
I don't know why.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|