Skip to content

Commit

Permalink
Support show_env param in /headers
Browse files Browse the repository at this point in the history
If `show_env` is True, then return all the headers without stripping `ENV_HEADERS`. This fixes postmanlabs#454.

Signed-off-by: Sanket Saurav <[email protected]>
  • Loading branch information
sanketsaurav committed May 19, 2018
1 parent 2f39ce3 commit 31ffe79
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
6 changes: 3 additions & 3 deletions httpbin/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,18 +282,18 @@ def view_uuid():

@app.route('/headers')
def view_headers():
"""Return the incoming requests's HTTP headers.
"""Return the incoming request's HTTP headers.
---
tags:
- Request inspection
produces:
- application/json
responses:
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')
Expand Down
24 changes: 24 additions & 0 deletions test_httpbin.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,30 @@ def test_set_cors_allow_headers(self):
self.assertEqual(
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):
response = self.app.get(
'/user-agent', headers={'User-Agent': 'test'}
Expand Down

0 comments on commit 31ffe79

Please sign in to comment.