Commits

Yohan Boniface committed c3dc5c0

Add Etag header to datalayer view

Comments (0)

Files changed (2)

leaflet_storage/tests/views.py

 
 class DataLayerViews(BaseTest):
 
+    def test_get(self):
+        url = reverse('datalayer_view', args=(self.datalayer.pk, ))
+        response = self.client.get(url)
+        self.assertIsNotNone(response['Etag'])
+        self.assertIsNotNone(response['Last-Modified'])
+        self.assertIsNotNone(response['Cache-Control'])
+        json = simplejson.loads(response.content)
+        self.assertIn('_storage', json)
+        self.assertIn('features', json)
+        self.assertEquals(json['type'], 'FeatureCollection')
+
     def test_update(self):
         url = reverse('datalayer_update', args=(self.map.pk, self.datalayer.pk))
         self.client.login(username=self.user.username, password="123123")

leaflet_storage/views.py

 # -*- coding:utf-8 -*-
 
 import os
+import hashlib
 
 from django.conf import settings
 from django.contrib import messages
             content_type='application/json'
         )
         response["Last-Modified"] = http_date(statobj.st_mtime)
+        response['ETag'] = '"%s"' % hashlib.md5(response.content).hexdigest()
         return response