mirror of
https://github.com/kennethreitz/httpbin.git
synced 2026-06-05 23:00:18 +00:00
Add a Brotli endpoint.
This commit is contained in:
@@ -204,6 +204,15 @@ def view_deflate_encoded_content():
|
||||
'origin', 'headers', method=request.method, deflated=True))
|
||||
|
||||
|
||||
@app.route('/brotli')
|
||||
@filters.brotli
|
||||
def view_brotli_encoded_content():
|
||||
"""Returns Brotli-Encoded Data."""
|
||||
|
||||
return jsonify(get_dict(
|
||||
'origin', 'headers', method=request.method, brotli=True))
|
||||
|
||||
|
||||
@app.route('/redirect/<int:n>')
|
||||
def redirect_n_times(n):
|
||||
"""302 Redirects n times."""
|
||||
|
||||
@@ -10,6 +10,8 @@ This module provides response filter decorators.
|
||||
import gzip as gzip2
|
||||
import zlib
|
||||
|
||||
import brotli as _brotli
|
||||
|
||||
from six import BytesIO
|
||||
from decimal import Decimal
|
||||
from time import time as now
|
||||
@@ -88,3 +90,26 @@ def deflate(f, *args, **kwargs):
|
||||
return data
|
||||
|
||||
return deflated_data
|
||||
|
||||
|
||||
@decorator
|
||||
def brotli(f, *args, **kwargs):
|
||||
"""Brotli Flask Response Decorator"""
|
||||
|
||||
data = f(*args, **kwargs)
|
||||
|
||||
if isinstance(data, Response):
|
||||
content = data.data
|
||||
else:
|
||||
content = data
|
||||
|
||||
deflated_data = _brotli.compress(content)
|
||||
|
||||
if isinstance(data, Response):
|
||||
data.data = deflated_data
|
||||
data.headers['Content-Encoding'] = 'brotli'
|
||||
data.headers['Content-Length'] = str(len(data.data))
|
||||
|
||||
return data
|
||||
|
||||
return deflated_data
|
||||
|
||||
@@ -32,5 +32,7 @@ setup(
|
||||
],
|
||||
packages=find_packages(),
|
||||
include_package_data = True, # include files listed in MANIFEST.in
|
||||
install_requires=['Flask','MarkupSafe','decorator','itsdangerous','six'],
|
||||
install_requires=[
|
||||
'Flask','MarkupSafe','decorator','itsdangerous','six','brotlipy'
|
||||
],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user