From d3d33de226ddbb6a93c4e1a5425bb98d4767f0f1 Mon Sep 17 00:00:00 2001 From: Brett Randall Date: Fri, 29 Jun 2018 21:19:50 +1000 Subject: [PATCH 1/2] redirect_to: Added url and status_code as query-string parameters for SwaggerUI. Fixed #476. --- httpbin/core.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/httpbin/core.py b/httpbin/core.py index 0a00a82..4922a8d 100644 --- a/httpbin/core.py +++ b/httpbin/core.py @@ -511,9 +511,12 @@ def redirect_to(): produces: - text/html parameters: - - name: url + - in: query + name: url type: string - - name: status_code + required: true + - in: query + name: status_code type: int responses: 302: From dd2513ae5940bc104d8bc4a9cab24a80304bd1db Mon Sep 17 00:00:00 2001 From: Brett Randall Date: Mon, 2 Jul 2018 15:04:44 +1000 Subject: [PATCH 2/2] redirect_to: split arg process for GET vs POST/PATCH/PUT, so the latter use formData for parameters. Fixed #476. POST/PUT only support formData body, not JSON. Note that PATCH parameters do not appear in Swagger 2 UI. --- httpbin/core.py | 56 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/httpbin/core.py b/httpbin/core.py index 4922a8d..ea0409b 100644 --- a/httpbin/core.py +++ b/httpbin/core.py @@ -510,20 +510,58 @@ def redirect_to(): - Redirects produces: - text/html - parameters: - - in: query - name: url - type: string - required: true - - in: query - 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