Skip to content

Commit

Permalink
GH-168: Add newline to end of page
Browse files Browse the repository at this point in the history
Fixes GH-168
  • Loading branch information
msabramo committed Nov 29, 2014
1 parent 128bc1b commit d8ad1d4
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import random
import base64

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
from werkzeug.http import http_date
from werkzeug.wrappers import BaseResponse
Expand All @@ -37,6 +37,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 @@ -24,6 +24,19 @@ def setUp(self):
httpbin.app.debug = True
self.app = httpbin.app.test_client()

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 d8ad1d4

Please sign in to comment.