前几天,在向Twitter发送请求后,我的客户端出现了一个奇怪的警告:
2018-01-12 02:32:50,162 WARN o.a.h.c.p.ResponseProcessCookies:130 - Invalid cookie header: "set-cookie: guest_id=v1%3A151572431977858379; Expires=Sun, 12 Jan 2020 02:31:59 UTC; Path=/; Domain=.twitter.com". Invalid 'expires' attribute: Sun, 12 Jan 2020 02:31:59 UTC
格式是正确的,所以最终是HTTP客户端配置错误,但这让我有了一个问题:为什么RESTful API会发送cookie?
这些似乎是Twitter的追踪cookie,在RESTful上下文中有什么用处呢?Twitter是否想在通过XMLHttpRequest调用时设置cookie(而不是在服务器端),还是他们错误地将通用的“设置cookie”过滤器也应用于API端点?
这个问题不仅适用于Twitter,还适用于一般的RESTful API。
以下是原始响应的摘录:
Server:
tsa_b
pragma:
no-cache
cache-control:
no-cache, no-store, must-revalidate, pre-check=0, post-check=0
x-connection-hash:
24fd4a4b3d61e33b6b94080b710a1e61
x-xss-protection:
1; mode=block; report=https://twitter.com/i/xss_report
x-content-type-options:
nosniff
x-rate-limit-limit:
900
expires:
Tue, 31 Mar 1981 05:00:00 GMT
Date:
Fri, 12 Jan 2018 17:45:03 GMT
set-cookie:
personalization_id="v1_/3EYpbQnCe+vnjhnBUew=="; Expires=Sun, 12 Jan 2020 17:45:03 UTC; Path=/; Domain=.twitter.com
set-cookie:
lang=en; Path=/
set-cookie:
guest_id=v1%3A1515770330954116; Expires=Sun, 12 Jan 2020 17:45:03 UTC; Path=/; Domain=.twitter.com
x-rate-limit-reset:
1515780003
content-disposition:
attachment; filename=json.json