mirror of
https://github.com/kennethreitz/httpbin.git
synced 2026-06-05 06:46:16 +00:00
GH-168: Add newline to end of page
Fixes GH-168
This commit is contained in:
+7
-1
@@ -14,7 +14,7 @@ import random
|
|||||||
import time
|
import time
|
||||||
import uuid
|
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.datastructures import WWWAuthenticate, MultiDict
|
||||||
from werkzeug.http import http_date
|
from werkzeug.http import http_date
|
||||||
from werkzeug.wrappers import BaseResponse
|
from werkzeug.wrappers import BaseResponse
|
||||||
@@ -36,6 +36,12 @@ ENV_COOKIES = (
|
|||||||
'__utmb'
|
'__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
|
# Prevent WSGI from correcting the casing of the Location header
|
||||||
BaseResponse.autocorrect_location_header = False
|
BaseResponse.autocorrect_location_header = False
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,19 @@ class HttpbinTestCase(unittest.TestCase):
|
|||||||
self.assertEqual(response.headers.get_all('animal'), ['dog', 'cat'])
|
self.assertEqual(response.headers.get_all('animal'), ['dog', 'cat'])
|
||||||
assert json.loads(response.data.decode('utf-8'))['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):
|
def test_base64(self):
|
||||||
greeting = u'Здравствуй, мир!'
|
greeting = u'Здравствуй, мир!'
|
||||||
b64_encoded = _string_to_base64(greeting)
|
b64_encoded = _string_to_base64(greeting)
|
||||||
|
|||||||
Reference in New Issue
Block a user