Skip to content

Commit

Permalink
Merge pull request postmanlabs#457 from sanketsaurav/454-fix-headers-…
Browse files Browse the repository at this point in the history
…view

Fix postmanlabs#454: Support `show_env` param in `/headers`
  • Loading branch information
kennethreitz authored Jul 4, 2018
2 parents 607ab22 + 31ffe79 commit ee15d0e
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 @@ -285,18 +285,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 ee15d0e

Please sign in to comment.