Commits

Robert Brewer  committed e8591b0

Backport of [2013] to branches/3.1.x.

  • Participants
  • Parent commits a3947d9
  • Branches cherrypy-3.1.x

Comments (0)

Files changed (2)

File cherrypy/_cptools.py

 _d.log_headers = Tool('before_error_response', cptools.log_request_headers)
 _d.log_hooks = Tool('on_end_request', cptools.log_hooks, priority=100)
 _d.err_redirect = ErrorTool(cptools.redirect)
-_d.etags = Tool('before_finalize', cptools.validate_etags)
+_d.etags = Tool('before_finalize', cptools.validate_etags, priority=75)
 _d.decode = Tool('before_handler', encoding.decode)
 # the order of encoding, gzip, caching is important
 _d.encode = Tool('before_finalize', encoding.encode, priority=70)

File cherrypy/test/test_etags.py

             else:
                 raise cherrypy.HTTPError(code)
         fail.exposed = True
+        
+        def unicoded(self):
+            return u'I am a \u1ee4nicode string.'
+        unicoded.exposed = True
+        unicoded._cp_config = {'tools.encode.on': True}
     
     conf = {'/': {'tools.etags.on': True,
-                  'tools.etags.autotags': True}}
+                  'tools.etags.autotags': True,
+                  }}
     cherrypy.tree.mount(Root(), config=conf)
     cherrypy.config.update({'environment': 'test_suite'})
 
 
 class ETagTest(helper.CPWebCase):
     
-    def testETags(self):
+    def test_etags(self):
         self.getPage("/resource")
         self.assertStatus('200 OK')
         self.assertHeader('Content-Type', 'text/html')
         self.assertStatus(304)
         self.getPage("/resource", headers=[('If-None-Match', "a bogus tag")])
         self.assertStatus("200 OK")
+    
+    def test_errors(self):
+        self.getPage("/resource")
+        self.assertStatus(200)
+        etag = self.assertHeader('ETag')
         
         # Test raising errors in page handler
         self.getPage("/fail/412", headers=[('If-Match', etag)])
         self.assertStatus(412)
         self.getPage("/fail/304", headers=[('If-None-Match', "*")])
         self.assertStatus(304)
+    
+    def test_unicode_body(self):
+        self.getPage("/unicoded")
+        self.assertStatus(200)
+        etag1 = self.assertHeader('ETag')
+        self.getPage("/unicoded", headers=[('If-Match', etag1)])
+        self.assertStatus(200)
+        self.assertHeader('ETag', etag1)
 
 
 if __name__ == "__main__":