Skip to content

Commit

Permalink
Merge branch 'GH-168' of https://github.com/msabramo/httpbin into msa…
Browse files Browse the repository at this point in the history
…bramo-GH-168
  • Loading branch information
johnsheehan committed Dec 23, 2014
2 parents 6930f82 + 24dadf0 commit 5858e3d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
8 changes: 7 additions & 1 deletion httpbin/core.py
Expand Up @@ -14,7 +14,7 @@
import time
import uuid

from flask import Flask, Response, request, render_template, redirect, jsonify, make_response
from flask import Flask, Response, request, render_template, redirect, jsonify as flask_jsonify, make_response
from werkzeug.datastructures import WWWAuthenticate, MultiDict
from werkzeug.http import http_date
from werkzeug.wrappers import BaseResponse
Expand All @@ -36,6 +36,12 @@
'__utmb'
)

def jsonify(*args, **kwargs):
response = flask_jsonify(*args, **kwargs)
if not response.data.endswith(b'\n'):
response.data += b'\n'
return response

# Prevent WSGI from correcting the casing of the Location header
BaseResponse.autocorrect_location_header = False

Expand Down
13 changes: 13 additions & 0 deletions test_httpbin.py
Expand Up @@ -36,6 +36,19 @@ def test_response_headers_multi(self):
self.assertEqual(response.headers.get_all('animal'), ['dog', 'cat'])
assert json.loads(response.data.decode('utf-8'))['animal'] == ['dog', 'cat']

def test_get(self):
response = self.app.get('/get', headers={'User-Agent': 'test'})
self.assertEqual(response.status_code, 200)
data = json.loads(response.data.decode('utf-8'))
self.assertEqual(data['args'], {})
self.assertEqual(data['headers']['Host'], 'localhost')
self.assertEqual(data['headers']['Content-Type'], '')
self.assertEqual(data['headers']['Content-Length'], '0')
self.assertEqual(data['headers']['User-Agent'], 'test')
self.assertEqual(data['origin'], None)
self.assertEqual(data['url'], 'http://localhost/get')
self.assertTrue(response.data.endswith(b'\n'))

def test_base64(self):
greeting = u'Здравствуй, мир!'
b64_encoded = _string_to_base64(greeting)
Expand Down

0 comments on commit 5858e3d

Please sign in to comment.