def gzipped_app(environ, start_response): status = "200 OK" encoded_body = list(gzip_app_iter([b'test'])) headers = [ ('Content-Type', str('text/html')), ('Content-Encoding', str('gzip')), ] start_response(str(status), headers) return encoded_body
def gzipped_app(environ, start_response): status = "200 OK" encoded_body = list(gzip_app_iter([b'test'])) headers = [ ('Content-Type', str('text/html')), ('Content-Encoding', str('gzip')), ] start_response(str(status), headers) return encoded_body
def test_gzip(self): app = self.app data = {"cell": [{"mcc": 1, "mnc": 2, "lac": 3, "cid": 4}]} body = ''.join(gzip_app_iter(dumps(data))) headers = { 'Content-Encoding': 'gzip', } res = app.post('/v1/search?key=test', body, headers=headers, content_type='application/json', status=200) self.assertEqual(res.content_type, 'application/json') self.assertEqual(res.json, {"status": "not_found"})
def gzipped_app(environ, start_response): status = "200 OK" encoded_body = list(gzip_app_iter([b'test'])) headers = [ ('Content-Type', str('text/html')), ('Content-Encoding', str('gzip')), ] # PEP 3333 requires native strings: headers = [(str(k), str(v)) for k, v in headers] start_response(str(status), headers) return encoded_body
def test_gzip(self): app = self.app data = {"items": [{"lat": 1.0, "lon": 2.0, "wifi": [{"key": "aaaaaaaaaaaa"}]}]} body = ''.join(gzip_app_iter(dumps(data))) headers = { 'Content-Encoding': 'gzip', } res = app.post('/v1/submit?key=test', body, headers=headers, content_type='application/json', status=204) self.assertEqual(res.body, '')
def test_compresses_streaming(self): decompressed_body = b"foofoofoofoofoofoofoofoofoofoofoofoofoofoo" compressed_body = b"".join(list(gzip_app_iter([decompressed_body]))) request = pretend.stub(accept_encoding=AcceptEncodingValidHeader("gzip")) response = Response(app_iter=iter([decompressed_body])) compressor(request, response) assert response.content_encoding == "gzip" assert response.content_length is None assert response.body == compressed_body
def test_gzip(self): app = self.app data = {"items": [{"lat": 1.0, "lon": 2.0, "wifi": [{"key": "aaaaaaaaaaaa"}]}]} body = ''.join(gzip_app_iter(dumps(data))) headers = { 'Content-Encoding': 'gzip', } res = app.post('/v1/submit?key=test', body, headers=headers, content_type='application/json', status=204) self.assertEqual(res.body, '')
def test_compresses_streaming_with_etag(self): decompressed_body = b"foofoofoofoofoofoofoofoofoofoofoofoofoofoo" compressed_body = b"".join(list(gzip_app_iter([decompressed_body]))) request = pretend.stub(accept_encoding=Accept("gzip")) response = Response(app_iter=iter([decompressed_body])) response.etag = "foo" compressor(request, response) assert response.content_encoding == "gzip" assert response.content_length is None assert response.body == compressed_body assert response.etag == "rfbezwKUdGjz6VPWDLDTvA"
def test_compresses_streaming_with_etag(self): decompressed_body = b"foofoofoofoofoofoofoofoofoofoofoofoofoofoo" compressed_body = b"".join(list(gzip_app_iter([decompressed_body]))) request = pretend.stub(accept_encoding=Accept("gzip")) response = Response(app_iter=iter([decompressed_body])) response.etag = "foo" compressor(request, response) assert response.content_encoding == "gzip" assert response.content_length is None assert response.body == compressed_body assert response.etag == "rfbezwKUdGjz6VPWDLDTvA"
def test_buffers_small_streaming(self): decompressed_body = b"foofoofoofoofoofoofoofoofoofoofoofoofoofoo" compressed_body = b"".join(list(gzip_app_iter([decompressed_body]))) request = pretend.stub(accept_encoding=Accept("gzip")) response = Response( app_iter=iter([decompressed_body]), content_length=len(decompressed_body), ) compressor(request, response) assert response.content_encoding == "gzip" assert response.content_length == len(compressed_body) assert response.body == compressed_body
def test_buffers_small_streaming(self): decompressed_body = b"foofoofoofoofoofoofoofoofoofoofoofoofoofoo" compressed_body = b"".join(list(gzip_app_iter([decompressed_body]))) request = pretend.stub(accept_encoding=Accept("gzip")) response = Response( app_iter=iter([decompressed_body]), content_length=len(decompressed_body), ) compressor(request, response) assert response.content_encoding == "gzip" assert response.content_length == len(compressed_body) assert response.body == compressed_body
def test_compresses_non_streaming(self): decompressed_body = b"foofoofoofoofoofoofoofoofoofoofoofoofoofoo" compressed_body = b"".join(list(gzip_app_iter([decompressed_body]))) request = pretend.stub(accept_encoding=AcceptEncodingValidHeader("gzip")) response = Response(body=decompressed_body) response.md5_etag() original_etag = response.etag compressor(request, response) assert response.content_encoding == "gzip" assert response.content_length == len(compressed_body) assert response.body == compressed_body assert response.etag != original_etag
def encode_gzip(data): # based on webob.response.Response.encode_content return ''.join(gzip_app_iter(data))