apiserver: add get_response_with_headers

This commit is contained in:
debugtalk
2017-06-21 13:19:31 +08:00
parent 8479a82983
commit 4a025164a6
2 changed files with 19 additions and 0 deletions

View File

@@ -27,6 +27,15 @@ def index():
def get_response_with_status_code(status_code):
return "Status Code: %d" % status_code, status_code
@app.route('/response_headers', methods=['POST'])
def get_response_with_headers():
headers_dict = request.get_json()
content = "Response headers: %s" % json.dumps(headers_dict)
response = make_response(content)
for header_key, header_value in headers_dict.items():
response.headers[header_key] = header_value
return response
@app.route('/api/users')
def get_users():
users_list = [user for uid, user in users_dict.items()]

View File

@@ -113,3 +113,13 @@ class TestApiServer(ApiServerUnittest):
url = "%s/status_code/%d" % (self.host, status_code)
resp = self.api_client.get(url)
self.assertEqual(status_code, resp.status_code)
def test_get_response_with_headers(self):
headers = {
'abc': 123,
'def': 456
}
url = "%s/response_headers" % self.host
resp = self.api_client.post(url, json=headers)
self.assertIn('abc', resp.headers)
self.assertIn('123', resp.headers['abc'])