def test_not_modified(self): r = http.not_modified() assert r.status.startswith("304") r = http.not_modified([("ETag", "123")]) assert r.status.startswith("304") assert r.headers["Content-Length"] == "0" assert r.body == ""
def test_not_modified(self): r = http.not_modified() assert r.status.startswith('304') r = http.not_modified([('ETag', '123')]) assert r.status.startswith('304') assert r.headers['Content-Length'] == '0' assert r.body == ''
def get_file(self, request, filestore_name, filename, etag): """ get the file through the cache and possibly resizing """ # Turn the filestore name into a filestore try: filestore = self.filestores[filestore_name] except KeyError: return None # Check the file is up to date try: cache_tag, headers, f = filestore.get(filename, etag) content_type = dict(headers)['Content-Type'] except KeyError: # XXX if the original is not their, clear resize cache (this would mean a globbing delete every request!) # cache_filename = filestore.name+'_'+filename # self.cache.delete(cache_filename, glob=True) return try: width, height, ismax = get_size_from_dict(request.GET) except ValueError: return http.bad_request() if request.GET.get('crop'): crop = True cropmark = '-crop' else: crop = False cropmark = '' size = get_size_suffix(width, height, ismax) if not size: if f: data = f.read() f.close() return http.ok([('Content-Type', content_type ),('ETag', cache_tag)], data) else: return http.not_modified([('ETag', cache_tag)]) try: cache_filename = (filestore_name or '')+'_'+filename+size+cropmark resized_cache_tag, headers, rf = self.cache.get(cache_filename, etag) content_type = dict(headers)['Content-Type'] resize_needed = resized_cache_tag != cache_tag if resize_needed and rf is not None: rf.close() except KeyError: resize_needed = True if resize_needed: if f is None: try: cache_tag, headers, f = filestore.get(filename) content_type = dict(headers)['Content-Type'] except KeyError: return rf = resize_image(f, (width, height), ismax, quality=self.resize_quality, crop=crop) f.close() self.cache.put(cache_filename, rf, cache_tag, [('Content-Type', content_type)]) rf.seek(0) data = rf.read() rf.close() return http.ok([('Content-Type', content_type ),('ETag', cache_tag)], data) if rf: data = rf.read() rf.close() return http.ok([('Content-Type', content_type ),('ETag', cache_tag)], data) else: return http.not_modified([('ETag', cache_tag)])
def test_not_modified(self): r = http.not_modified() assert r.status.startswith('304') r = http.not_modified([('ETag', '123')]) assert r.status.startswith('304') assert r.headers['ETag'] == '123'