Skip to content

Commit f8a7a62

Browse files
committed
Revert "no rate limiting"
This reverts commit f1042e3.
1 parent f1042e3 commit f8a7a62

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Pipfile

+3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ gunicorn = "*"
77
decorator = "*"
88
brotlipy = "*"
99
gevent = "*"
10+
redis = "*"
11+
hiredis = "*"
1012
Flask = "*"
13+
Flask-Limiter = "*"
1114

1215
[packages.raven]
1316
extras = [ "flask",]

httpbin/core.py

+16
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import argparse
1717

1818
from flask import Flask, Response, request, render_template, redirect, jsonify as flask_jsonify, make_response, url_for
19+
from flask_limiter import Limiter
20+
from flask_limiter.util import get_ipaddr
1921
from six.moves import range as xrange
2022
from werkzeug.datastructures import WWWAuthenticate, MultiDict
2123
from werkzeug.http import http_date
@@ -57,6 +59,20 @@ def jsonify(*args, **kwargs):
5759
if 'SENTRY_DSN' in os.environ:
5860
sentry = Sentry(app, dsn=os.environ['SENTRY_DSN'])
5961

62+
# Setup rate-limiting.
63+
if 'REDIS_URL' in os.environ:
64+
app.config['RATELIMIT_STORAGE_URL'] = os.environ['REDIS_URL']
65+
app.config['RATELIMIT_HEADERS_ENABLED'] = True
66+
67+
limiter = Limiter(
68+
app,
69+
key_func=get_ipaddr,
70+
global_limits=["100000 per day", "10000 per hour"]
71+
)
72+
73+
74+
75+
6076
# Set up Bugsnag exception tracking, if desired. To use Bugsnag, install the
6177
# Bugsnag Python client with the command "pip install bugsnag", and set the
6278
# environment variable BUGSNAG_API_KEY. You can also optionally set

0 commit comments

Comments
 (0)