Page MenuHomePhabricator
Paste P5212

no-CT-on-304s.patch
ActivePublic

Authored by ema on Apr 6 2017, 9:35 AM.
Tags
None
Referenced Files
F7298955: no-CT-on-304s.patch
Apr 6 2017, 9:35 AM
Subscribers
Description: Do not return Content-Type on 304 responses
According to RFC 7232 section 4.1, 304 Not Modified responses shouldn't
include representation metadata other than Cache-Control, Content-Location,
Date, ETag, Expires, Vary and possibly Last-Modified. Thus, swift should stop
returning Content-Type on 304s.
Author: Emanuele Rocca <ema@wikimedia.org>
Bug: https://phabricator.wikimedia.org/T162348
Bug: https://phabricator.wikimedia.org/T162035
--- swift-2.2.0.orig/swift/common/swob.py
+++ swift-2.2.0/swift/common/swob.py
@@ -1307,6 +1307,8 @@ class Response(object):
if 'location' in self.headers and \
not env.get('swift.leave_relative_location'):
self.location = self.absolute_location()
+ if self.status_int == 304 and 'Content-Type' in self.headers:
+ self.headers.pop('Content-Type')
start_response(self.status, self.headers.items())
return app_iter

Event Timeline

Just nitpicking, pop() is returning the value that of course you don't need, for how the HeaderKeyDict is implemented.
There is a __delitem__ implemented that you could use with del self.headers['Content-Type'] if I'm not mistaken.