From 16f7ab8c7060025bbbf8a63e76ae5d3da897c654 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Sun, 26 Feb 2012 22:23:02 -0800 Subject: [PATCH 1/3] Remove very broken JSON stuff --- httpbin/helpers.py | 5 +++-- run_httpbin.py | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/httpbin/helpers.py b/httpbin/helpers.py index fc899e7..3b73c8f 100644 --- a/httpbin/helpers.py +++ b/httpbin/helpers.py @@ -7,6 +7,7 @@ httpbin.helpers This module provides helper functions for httpbin. """ +import json from hashlib import md5 from werkzeug.http import parse_authorization_header @@ -95,9 +96,9 @@ def get_dict(*keys, **extras): form = nonflat_dict try: - json = json.loads(request.data) + json_input = json.loads(request.data) except ValueError: - json = None + json_input = None d = dict( diff --git a/run_httpbin.py b/run_httpbin.py index 1b44eea..1f604b3 100755 --- a/run_httpbin.py +++ b/run_httpbin.py @@ -12,5 +12,6 @@ except (IndexError, ValueError): port = 5000 print 'Starting httpbin on port {0}'.format(port) +app.debug = True http_server = WSGIServer(('', port), app) -http_server.serve_forever() \ No newline at end of file +http_server.serve_forever() From 38d04e0bb9544a1516fc49c08a7c28b1f68a304a Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Sun, 26 Feb 2012 22:35:36 -0800 Subject: [PATCH 2/3] Show proper scheme in urls --- httpbin/helpers.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/httpbin/helpers.py b/httpbin/helpers.py index 3b73c8f..86a3676 100644 --- a/httpbin/helpers.py +++ b/httpbin/helpers.py @@ -6,7 +6,6 @@ httpbin.helpers This module provides helper functions for httpbin. """ - import json from hashlib import md5 from werkzeug.http import parse_authorization_header @@ -73,6 +72,11 @@ def get_headers(hide_env=True): return CaseInsensitiveDict(headers.items()) +def get_url(): + scheme = request.headers.get("X-Forwarded-Proto", "http") + return request.url.replace("http", scheme) + + def get_dict(*keys, **extras): """Returns request dict of given keys.""" @@ -102,7 +106,7 @@ def get_dict(*keys, **extras): d = dict( - url=request.url, + url=get_url(), args=request.args, form=form, data=data, From 5eb1c9ad0d1cf18b676ffa270d5b390c15a5d247 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Sun, 26 Feb 2012 22:38:17 -0800 Subject: [PATCH 3/3] Remove app.debug --- run_httpbin.py | 1 - 1 file changed, 1 deletion(-) diff --git a/run_httpbin.py b/run_httpbin.py index 1f604b3..282006d 100755 --- a/run_httpbin.py +++ b/run_httpbin.py @@ -12,6 +12,5 @@ except (IndexError, ValueError): port = 5000 print 'Starting httpbin on port {0}'.format(port) -app.debug = True http_server = WSGIServer(('', port), app) http_server.serve_forever()