我一直在尝试对 HTTP 响应标头进行单元测试。我需要从标头接收 cookie。我得到了两个Set-Cookie
标题,但我需要一个用于身份验证。返回的标头是:
HTTP/1.1 200 OK
Server: Cowboy
Connection: close
Set-Cookie: heroku-session-affinity=ADaDaANoA24IARpRKtf///8HYgABgzdiAAJZ5WECbAAAAAJtAAAABXdlYi4ybQAAAAV3ZWIuMWpcXMFamSToBPxyiOHM7o5AwvVZ3g__; Version=1; Expires=Thu, 12-Jan-2017 01:45:27 GMT; Max-Age=86400; Domain=xxxxxxxx.xxxx.xx; Path=/; HttpOnly
X-Powered-By: Express
Vary: Origin
Access-Control-Allow-Credentials: true
Content-Type: application/json; charset=utf-8
Content-Length: 30914
Etag: W/"78c2-veX2kgrO3zh118nYsOP80A"
Set-Cookie: connect.sid=s%3Adl1_47SY9vlKlHOguBvjZpmaa2WTUhHG.O2j9YOShB4AX0rAC5RRj%2BeCXAB11s5q1DB4x4fiHE4A; Path=/; Expires=Fri, 13 Jan 2017 01:45:27 GMT; HttpOnly
Date: Wed, 11 Jan 2017 01:45:27 GMT
Via: 1.1 vegur
我添加了一个包含这些值的测试文件:
{
"Server": "Cowboy",
"Connection": "close",
"Set-Cookie": "heroku-session-affinity=ADaDaANoA24IAXtpQOD///8HYgAAKehiAA6V12ECbAAAAAJtAAAABXdlYi4ybQAAAAV3ZWIuMWrNqkap0u4H0uG3Btrtlamaq2nQ5w__; Version=1; Expires=Wed, 11-Jan-2017 01:12:09 GMT; Max-Age=86400; Domain=xxxxxxxx.xxxx.xx; Path=/; HttpOnly",
"X-Powered-By": "Express",
"Vary": "Origin",
"Access-Control-Allow-Credentials": "true",
"Content-Type": "application/json; charset=utf-8",
"Content-Length": "30914",
"Etag": "W/\"78c2-veX2kgrO3zh118nYsOP80A\"",
"Set-Cookie": "connect.sid=s%3ACX3tfhPk9nlRtU8e8gtouQIx1kpP07h9.iExm%2F96Dgzuh289nmjwbYO49E0Bq0WwUHmN539IkudI; Path=/; Expires=Thu, 12 Jan 2017 01:12:09 GMT; HttpOnly",
"Date": "Tue, 10 Jan 2017 01:12:09 GMT",
"Via": "1.1 vegur"
}
我需要第二个Set-Cookie
值,但是当我尝试访问它的值时,我得到了第一个值Set-Cookie
。我假设是因为我将标题放在字典中。但是当我在单元测试中存根响应时,标题所需的格式是字典。我只得到一个Set-Cookie
标题,因为我不能在字典中拥有两个相同的键。
我做错了什么吗?