mirror of
https://github.com/kennethreitz/httpbin.git
synced 2026-06-05 06:46:16 +00:00
Support show_env param in /headers
If `show_env` is True, then return all the headers without stripping `ENV_HEADERS`. This fixes #454. Signed-off-by: Sanket Saurav <sanketsaurav@gmail.com>
This commit is contained in:
+3
-3
@@ -282,7 +282,7 @@ def view_uuid():
|
|||||||
|
|
||||||
@app.route('/headers')
|
@app.route('/headers')
|
||||||
def view_headers():
|
def view_headers():
|
||||||
"""Return the incoming requests's HTTP headers.
|
"""Return the incoming request's HTTP headers.
|
||||||
---
|
---
|
||||||
tags:
|
tags:
|
||||||
- Request inspection
|
- Request inspection
|
||||||
@@ -290,10 +290,10 @@ def view_headers():
|
|||||||
- application/json
|
- application/json
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: The Rrquest's IP Address.
|
description: The request's headers.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return jsonify(get_dict('headers'))
|
return jsonify(get_headers())
|
||||||
|
|
||||||
|
|
||||||
@app.route('/user-agent')
|
@app.route('/user-agent')
|
||||||
|
|||||||
@@ -265,6 +265,30 @@ class HttpbinTestCase(unittest.TestCase):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
response.headers.get('Access-Control-Allow-Headers'), 'X-Test-Header'
|
response.headers.get('Access-Control-Allow-Headers'), 'X-Test-Header'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_headers(self):
|
||||||
|
headers = {
|
||||||
|
"Accept": "*/*",
|
||||||
|
"Host": "localhost:1234",
|
||||||
|
"User-Agent": "curl/7.54.0",
|
||||||
|
"Via": "bar"
|
||||||
|
}
|
||||||
|
response = self.app.get('/headers', headers=headers)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertTrue({'Accept', 'Host', 'User-Agent'}.issubset(set(response.json.keys())))
|
||||||
|
self.assertNotIn('Via', response.json)
|
||||||
|
|
||||||
|
def test_headers_show_env(self):
|
||||||
|
headers = {
|
||||||
|
"Accept": "*/*",
|
||||||
|
"Host": "localhost:1234",
|
||||||
|
"User-Agent": "curl/7.54.0",
|
||||||
|
"Via": "bar"
|
||||||
|
}
|
||||||
|
response = self.app.get('/headers?show_env=true', headers=headers)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertTrue({'Accept', 'Host', 'User-Agent', 'Via'}.issubset(set(response.json.keys())))
|
||||||
|
|
||||||
def test_user_agent(self):
|
def test_user_agent(self):
|
||||||
response = self.app.get(
|
response = self.app.get(
|
||||||
'/user-agent', headers={'User-Agent': 'test'}
|
'/user-agent', headers={'User-Agent': 'test'}
|
||||||
|
|||||||
Reference in New Issue
Block a user