diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9414382 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +Dockerfile diff --git a/.gitignore b/.gitignore index ec156a9..ea1169a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ dist/ .tox *.egg-info *.swp +.vscode/ diff --git a/Dockerfile b/Dockerfile index 681bcd7..541f4cd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,10 @@ FROM ubuntu:18.04 +LABEL name="httpbin" +LABEL version="0.9.0" +LABEL description="A simple HTTP service." +LABEL org.kennethreitz.vendor="Kenneth Reitz" + RUN apt update -y && apt install python3-pip -y EXPOSE 80 diff --git a/MANIFEST.in b/MANIFEST.in index a2b13cf..894af4c 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,3 @@ -include httpbin/VERSION README.rst LICENSE AUTHORS requirements.txt test_httpbin.py +include httpbin/VERSION README.md LICENSE AUTHORS test_httpbin.py recursive-include httpbin/templates * recursive-include httpbin/static * diff --git a/httpbin/core.py b/httpbin/core.py index d1b3ead..fdee126 100644 --- a/httpbin/core.py +++ b/httpbin/core.py @@ -58,6 +58,7 @@ tmpl_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates') app = Flask(__name__, template_folder=tmpl_dir) app.debug = bool(os.environ.get('DEBUG')) +app.config['JSONIFY_PRETTYPRINT_REGULAR'] = True app.add_template_global('HTTPBIN_TRACKING' in os.environ, name='tracking_enabled') @@ -86,8 +87,7 @@ template = { "host": "httpbin.org", # overrides localhost:5000 "basePath": "/", # base bash for blueprint registration "schemes": [ - "https", - "http" + "https" ], 'protocol': 'https', 'tags': [ @@ -513,17 +513,58 @@ def redirect_to(): - Redirects produces: - text/html - parameters: - - name: url - type: string - - name: status_code - type: int + get: + parameters: + - in: query + name: url + type: string + required: true + - in: query + name: status_code + type: int + post: + consumes: + - application/x-www-form-urlencoded + parameters: + - in: formData + name: url + type: string + required: true + - in: formData + name: status_code + type: int + required: false + patch: + consumes: + - application/x-www-form-urlencoded + parameters: + - in: formData + name: url + type: string + required: true + - in: formData + name: status_code + type: int + required: false + put: + consumes: + - application/x-www-form-urlencoded + parameters: + - in: formData + name: url + type: string + required: true + - in: formData + name: status_code + type: int + required: false responses: 302: description: A redirection. """ - args = CaseInsensitiveDict(request.args.items()) + argsDict = request.form.to_dict(flat=True) if request.method in ('POST', 'PATCH', 'PUT') else request.args.items() + args = CaseInsensitiveDict(argsDict) # We need to build the response manually and convert to UTF-8 to prevent # werkzeug from "fixing" the URL. This endpoint should set the Location @@ -1075,7 +1116,7 @@ def digest_auth(qop=None, user='user', passwd='passwd', algorithm='MD5', stale_a return response -@app.route('/delay/') +@app.route('/delay/', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'TRACE']) def delay_response(delay): """"Returns a delayed response (max of 10 seconds). --- @@ -1105,6 +1146,31 @@ def drip(): --- tags: - Dynamic data + parameters: + - in: query + name: duration + type: number + description: The amount of time (in seconds) over which to drip each byte + default: 2 + required: false + - in: query + name: numbytes + type: integer + description: The number of bytes to respond with + default: 10 + required: false + - in: query + name: code + type: integer + description: The response code that will be returned + default: 200 + required: false + - in: query + name: delay + type: number + description: The amount of time (in seconds) to delay before responding + default: 2 + required: false produces: - application/octet-stream responses: @@ -1127,7 +1193,7 @@ def drip(): pause = duration / numbytes def generate_bytes(): for i in xrange(numbytes): - yield u"*".encode('utf-8') + yield b"*" time.sleep(pause) response = Response(generate_bytes(), headers={ diff --git a/httpbin/templates/index.html b/httpbin/templates/index.html index 7fbae03..0348536 100644 --- a/httpbin/templates/index.html +++ b/httpbin/templates/index.html @@ -1,70 +1,251 @@ + httpbin(1): HTTP Client Testing Service - - - + + + -{% include 'httpbin.1.html' %} - -{% if tracking_enabled %} - {% include 'trackingscripts.html' %} -{% endif %} + {% include 'httpbin.1.html' %} {% if tracking_enabled %} {% include 'trackingscripts.html' %} {% endif %} + diff --git a/now.json b/now.json new file mode 100644 index 0000000..26fd17f --- /dev/null +++ b/now.json @@ -0,0 +1,10 @@ +{ + "name": "httpbin", + "regions": [ + "all" + ], + "alias": [ + "httpbin.org" + ], + "type": "docker" +}