From ef9c3948e8cd8f95cad9a908b0a46cb5a633d480 Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Fri, 28 Nov 2014 16:36:42 -0800 Subject: [PATCH 1/6] Imports; remove dup base64, alpha sort --- httpbin/core.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/httpbin/core.py b/httpbin/core.py index 2e8774b..3b7faaf 100644 --- a/httpbin/core.py +++ b/httpbin/core.py @@ -10,10 +10,9 @@ This module provides the core HttpBin experience. import base64 import json import os +import random import time import uuid -import random -import base64 from flask import Flask, Response, request, render_template, redirect, jsonify, make_response from werkzeug.datastructures import WWWAuthenticate From 3c40fab03b0b9da315b98e04a35da8aab6cae534 Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Sat, 29 Nov 2014 00:03:29 -0800 Subject: [PATCH 2/6] GH-162: No 500 w/ better handle missing dict keys --- httpbin/helpers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/httpbin/helpers.py b/httpbin/helpers.py index b2264d3..89bef12 100644 --- a/httpbin/helpers.py +++ b/httpbin/helpers.py @@ -297,7 +297,7 @@ def response(credentails, password, request): if credentails.get('qop') is None: response = H(b":".join([ HA1_value.encode('utf-8'), - credentails.get('nonce').encode('utf-8'), + credentails.get('nonce', '').encode('utf-8'), HA2_value.encode('utf-8') ])) elif credentails.get('qop') == 'auth' or credentails.get('qop') == 'auth-int': @@ -326,6 +326,6 @@ def check_digest_auth(user, passwd): response_hash = response(credentails, passwd, dict(uri=request.path, body=request.data, method=request.method)) - if credentails['response'] == response_hash: + if credentails.get('response') == response_hash: return True return False From 941033ddd29359ddfed6a231487680fbbccc51c3 Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Sat, 29 Nov 2014 06:18:52 -0800 Subject: [PATCH 3/6] GH-125: Support multiple headers with same key Fixes: GH-125 --- httpbin/core.py | 18 ++++++++++++------ test_httpbin.py | 12 ++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/httpbin/core.py b/httpbin/core.py index 2e8774b..79719dd 100644 --- a/httpbin/core.py +++ b/httpbin/core.py @@ -16,7 +16,7 @@ import random import base64 from flask import Flask, Response, request, render_template, redirect, jsonify, make_response -from werkzeug.datastructures import WWWAuthenticate +from werkzeug.datastructures import WWWAuthenticate, MultiDict from werkzeug.http import http_date from werkzeug.wrappers import BaseResponse from six.moves import range as xrange @@ -267,14 +267,20 @@ def view_status_code(codes): @app.route('/response-headers') def response_headers(): """Returns a set of response headers from the query string """ - headers = CaseInsensitiveDict(request.args.items()) - response = jsonify(headers.items()) + headers = MultiDict(request.args.items(multi=True)) + response = jsonify(headers.lists()) while True: content_len_shown = response.headers['Content-Length'] - response = jsonify(response.headers.items()) - for key, value in headers.items(): - response.headers[key] = value + d = {} + for key in response.headers.keys(): + value = response.headers.get_all(key) + if len(value) == 1: + value = value[0] + d[key] = value + response = jsonify(d) + for key, value in headers.items(multi=True): + response.headers.add(key, value) if response.headers['Content-Length'] == content_len_shown: break return response diff --git a/test_httpbin.py b/test_httpbin.py index 8af40d8..9adc7dd 100755 --- a/test_httpbin.py +++ b/test_httpbin.py @@ -24,6 +24,18 @@ class HttpbinTestCase(unittest.TestCase): httpbin.app.debug = True self.app = httpbin.app.test_client() + def test_response_headers_simple(self): + response = self.app.get('/response-headers?animal=dog') + self.assertEqual(response.status_code, 200) + self.assertEqual(response.headers.get_all('animal'), ['dog']) + assert json.loads(response.data.decode('utf-8'))['animal'] == 'dog' + + def test_response_headers_multi(self): + response = self.app.get('/response-headers?animal=dog&animal=cat') + self.assertEqual(response.status_code, 200) + self.assertEqual(response.headers.get_all('animal'), ['dog', 'cat']) + assert json.loads(response.data.decode('utf-8'))['animal'] == ['dog', 'cat'] + def test_base64(self): greeting = u'Здравствуй, мир!' b64_encoded = _string_to_base64(greeting) From a9cfa4452eed1966ea714cdead0456a9b47d5718 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Mon, 15 Dec 2014 14:21:19 -0600 Subject: [PATCH 4/6] Update repository URL in app.json Fixes #174 --- app.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.json b/app.json index be600b4..7fa1493 100644 --- a/app.json +++ b/app.json @@ -1,7 +1,7 @@ { "name": "httpbin", "description": "HTTP Request & Response Service, written in Python + Flask.", - "repository": "https://github.com/kennethreitz/httpbin", + "repository": "https://github.com/Runscope/httpbin", "website": "https://httpbin.org", "logo": "https://s3.amazonaws.com/f.cl.ly/items/333Y191Z2C0G2J3m3Y0b/httpbin.svg", "keywords": ["http", "rest", "API", "testing", "integration", "python", "flask"] From bf09ea0f5aebc50e41460753014cc5fef3df10db Mon Sep 17 00:00:00 2001 From: Mark Norgren Date: Mon, 15 Dec 2014 15:25:13 -0600 Subject: [PATCH 5/6] Update Readme for Deploy to Heroku button fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 07ca81f..aa4f360 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ httpbin(1): HTTP Request & Response Service Freely hosted in [HTTP](http://httpbin.org), [HTTPS](https://httpbin.org) & [EU](http://eu.httpbin.org/) flavors by [Runscope](https://www.runscope.com/) -[![Deploy to Heroku](https://camo.githubusercontent.com/c0824806f5221ebb7d25e559568582dd39dd1170/68747470733a2f2f7777772e6865726f6b7563646e2e636f6d2f6465706c6f792f627574746f6e2e706e67)](https://heroku.com/deploy?template=https://github.com/kennethreitz/httpbin) +[![Deploy to Heroku](https://camo.githubusercontent.com/c0824806f5221ebb7d25e559568582dd39dd1170/68747470733a2f2f7777772e6865726f6b7563646e2e636f6d2f6465706c6f792f627574746f6e2e706e67)](https://heroku.com/deploy?template=https://github.com/Runscope/httpbin) ## ENDPOINTS From 79d62dbaef3791e7017209ef6a425b881a422443 Mon Sep 17 00:00:00 2001 From: Mark Norgren Date: Mon, 15 Dec 2014 15:47:12 -0600 Subject: [PATCH 6/6] Update httpbin.1.html --- httpbin/templates/httpbin.1.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/httpbin/templates/httpbin.1.html b/httpbin/templates/httpbin.1.html index 370bac2..08a7777 100644 --- a/httpbin/templates/httpbin.1.html +++ b/httpbin/templates/httpbin.1.html @@ -2,7 +2,7 @@

httpbin(1): HTTP Request & Response Service

Freely hosted in HTTP, HTTPS & EU flavors by Runscope

-

Deploy to Heroku

+

Deploy to Heroku

ENDPOINTS