@@ -941,7 +941,6 @@ func Test_Ctx_Cookie_PartitionedSecure(t *testing.T) {
941941func Test_Ctx_Cookie_Invalid (t * testing.T ) {
942942 t .Parallel ()
943943 app := New ()
944- c := app .AcquireCtx (& fasthttp.RequestCtx {})
945944
946945 cases := []* Cookie {
947946 {Name : "" , Value : "a" }, // empty name
@@ -956,10 +955,71 @@ func Test_Ctx_Cookie_Invalid(t *testing.T) {
956955 }
957956
958957 for _ , invalid := range cases {
958+ c := app .AcquireCtx (& fasthttp.RequestCtx {})
959959 c .Res ().Cookie (invalid )
960960 require .Empty (t , c .Res ().Get (HeaderSetCookie ))
961961 c .Response ().Header .Reset ()
962+ app .ReleaseCtx (c )
963+ }
964+ }
965+
966+ // go test -run Test_Ctx_Cookie_DefaultPath
967+ func Test_Ctx_Cookie_DefaultPath (t * testing.T ) {
968+ t .Parallel ()
969+ app := New ()
970+ c := app .AcquireCtx (& fasthttp.RequestCtx {})
971+
972+ ck := & Cookie {
973+ Name : "p" ,
974+ Value : "v" ,
975+ // Path intentionally empty to verify defaulting
976+ }
977+
978+ c .Res ().Cookie (ck )
979+ require .Equal (t ,
980+ "p=v; path=/; SameSite=Lax" ,
981+ c .Res ().Get (HeaderSetCookie ),
982+ )
983+ }
984+
985+ // go test -run Test_Ctx_Cookie_MaxAgeOnly
986+ func Test_Ctx_Cookie_MaxAgeOnly (t * testing.T ) {
987+ t .Parallel ()
988+ app := New ()
989+ c := app .AcquireCtx (& fasthttp.RequestCtx {})
990+
991+ ck := & Cookie {
992+ Name : "ttl" ,
993+ Value : "v" ,
994+ MaxAge : 3600 ,
962995 }
996+ c .Res ().Cookie (ck )
997+
998+ require .Equal (t ,
999+ "ttl=v; Max-Age=3600; path=/; SameSite=Lax" ,
1000+ c .Res ().Get (HeaderSetCookie ),
1001+ )
1002+ }
1003+
1004+ // go test -run Test_Ctx_Cookie_StrictPartitioned
1005+ func Test_Ctx_Cookie_StrictPartitioned (t * testing.T ) {
1006+ t .Parallel ()
1007+ app := New ()
1008+ c := app .AcquireCtx (& fasthttp.RequestCtx {})
1009+
1010+ ck := & Cookie {
1011+ Name : "sp" ,
1012+ Value : "v" ,
1013+ Secure : true ,
1014+ SameSite : CookieSameSiteStrictMode ,
1015+ Partitioned : true ,
1016+ }
1017+ c .Res ().Cookie (ck )
1018+
1019+ require .Equal (t ,
1020+ "sp=v; path=/; secure; SameSite=Strict; Partitioned" ,
1021+ c .Res ().Get (HeaderSetCookie ),
1022+ )
9631023}
9641024
9651025// go test -v -run=^$ -bench=Benchmark_Ctx_Cookie -benchmem -count=4
0 commit comments