Anonymous avatar Anonymous committed cdc7ce2

Added some more arguments to Request.remove_conditional_headers. This is useful for middleware that wants to modify the body of the response, but still wants to use the Etag / If-Modified-Since logic of the wrapped app.

Comments (0)

Files changed (1)


         env['REQUEST_METHOD'] = 'GET'
         return self.__class__(env)
-    def remove_conditional_headers(self, remove_encoding=True):
+    def remove_conditional_headers(self, remove_encoding=True, remove_range=True,
+                                        remove_match=True, remove_modified=True):
         Remove headers that make the request conditional.
         This does not remove headers like If-Match, which are used for
         conflict detection.
-        for key in ['HTTP_IF_MATCH', 'HTTP_IF_MODIFIED_SINCE',
-                    'HTTP_IF_RANGE', 'HTTP_RANGE']:
+        check_keys = []
+        if remove_range:
+            check_keys += ['HTTP_IF_RANGE', 'HTTP_RANGE']
+        if remove_match:
+            check_keys.append('HTTP_IF_MATCH')
+        if remove_modified:
+            check_keys.append('HTTP_IF_MODIFIED_SINCE')
+        if remove_encoding:
+            check_keys.append('HTTP_ACCEPT_ENCODING')
+        for key in check_keys:
             if key in self.environ:
                 del self.environ[key]
-        if remove_encoding:
-            if 'HTTP_ACCEPT_ENCODING' in self.environ:
-                del self.environ['HTTP_ACCEPT_ENCODING']
     accept = converter(
         environ_getter('HTTP_ACCEPT', rfc_section='14.1'),
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.