Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Commit 8391a3c

Browse files
committed
Keep ResponseCookie options on delete. (#905)
1 parent 4a5a07a commit 8391a3c

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/Microsoft.AspNetCore.Http/Internal/ResponseCookies.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ public void Delete(string key, CookieOptions options)
129129
Path = options.Path,
130130
Domain = options.Domain,
131131
Expires = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc),
132+
Secure = options.Secure,
133+
HttpOnly = options.HttpOnly,
134+
SameSite = options.SameSite
132135
});
133136
}
134137
}

test/Microsoft.AspNetCore.Http.Tests/ResponseCookiesTest.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
45
using System.Text;
56
using Microsoft.AspNetCore.Http.Internal;
67
using Microsoft.Extensions.ObjectPool;
@@ -27,6 +28,35 @@ public void DeleteCookieShouldSetDefaultPath()
2728
Assert.Contains("expires=Thu, 01 Jan 1970 00:00:00 GMT", cookieHeaderValues[0]);
2829
}
2930

31+
[Fact]
32+
public void DeleteCookieWithCookieOptionsShouldKeepPropertiesOfCookieOptions()
33+
{
34+
var headers = new HeaderDictionary();
35+
var cookies = new ResponseCookies(headers, null);
36+
var testcookie = "TestCookie";
37+
var time = new DateTimeOffset(2000, 1, 1, 1, 1, 1, 1, TimeSpan.Zero);
38+
var options = new CookieOptions
39+
{
40+
Secure = true,
41+
HttpOnly = true,
42+
Path = "/",
43+
Expires = time,
44+
Domain = "example.com",
45+
SameSite = SameSiteMode.Lax
46+
};
47+
48+
cookies.Delete(testcookie, options);
49+
50+
var cookieHeaderValues = headers[HeaderNames.SetCookie];
51+
Assert.Equal(1, cookieHeaderValues.Count);
52+
Assert.StartsWith(testcookie, cookieHeaderValues[0]);
53+
Assert.Contains("path=/", cookieHeaderValues[0]);
54+
Assert.Contains("expires=Thu, 01 Jan 1970 00:00:00 GMT", cookieHeaderValues[0]);
55+
Assert.Contains("secure", cookieHeaderValues[0]);
56+
Assert.Contains("httponly", cookieHeaderValues[0]);
57+
Assert.Contains("samesite", cookieHeaderValues[0]);
58+
}
59+
3060
[Fact]
3161
public void NoParamsDeleteRemovesCookieCreatedByAdd()
3262
{

0 commit comments

Comments
 (0)