mirror of
https://github.com/kennethreitz/httpbin.git
synced 2026-06-05 06:46:16 +00:00
Merge branch 'master' of github.com:Runscope/httpbin
This commit is contained in:
@@ -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/)
|
||||
|
||||
|
||||
[](https://heroku.com/deploy?template=https://github.com/kennethreitz/httpbin)
|
||||
[](https://heroku.com/deploy?template=https://github.com/Runscope/httpbin)
|
||||
|
||||
## ENDPOINTS
|
||||
|
||||
|
||||
@@ -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"]
|
||||
|
||||
+13
-8
@@ -10,13 +10,12 @@ 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 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 +266,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
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<h1>httpbin(1): HTTP Request & Response Service</h1>
|
||||
<p>Freely hosted in <a href="http://httpbin.org">HTTP</a>, <a href="https://httpbin.org">HTTPS</a> & <a href="http://eu.httpbin.org/">EU</a> flavors by <a href="https://www.runscope.com/">Runscope</a></p>
|
||||
|
||||
<p><a href="https://heroku.com/deploy?template=https://github.com/kennethreitz/httpbin"><img src="https://camo.githubusercontent.com/c0824806f5221ebb7d25e559568582dd39dd1170/68747470733a2f2f7777772e6865726f6b7563646e2e636f6d2f6465706c6f792f627574746f6e2e706e67" alt="Deploy to Heroku" /></a></p>
|
||||
<p><a href="https://heroku.com/deploy?template=https://github.com/Runscope/httpbin"><img src="https://camo.githubusercontent.com/c0824806f5221ebb7d25e559568582dd39dd1170/68747470733a2f2f7777772e6865726f6b7563646e2e636f6d2f6465706c6f792f627574746f6e2e706e67" alt="Deploy to Heroku" /></a></p>
|
||||
|
||||
<h2 id="ENDPOINTS">ENDPOINTS</h2>
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user