Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-168: Add newline to end of page #173

Merged
merged 1 commit into from
Dec 23, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion httpbin/core.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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