mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-07 00:17:37 +08:00
apiserver: add get_response_with_headers
This commit is contained in:
@@ -27,6 +27,15 @@ def index():
|
|||||||
def get_response_with_status_code(status_code):
|
def get_response_with_status_code(status_code):
|
||||||
return "Status Code: %d" % 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')
|
@app.route('/api/users')
|
||||||
def get_users():
|
def get_users():
|
||||||
users_list = [user for uid, user in users_dict.items()]
|
users_list = [user for uid, user in users_dict.items()]
|
||||||
|
|||||||
@@ -113,3 +113,13 @@ class TestApiServer(ApiServerUnittest):
|
|||||||
url = "%s/status_code/%d" % (self.host, status_code)
|
url = "%s/status_code/%d" % (self.host, status_code)
|
||||||
resp = self.api_client.get(url)
|
resp = self.api_client.get(url)
|
||||||
self.assertEqual(status_code, resp.status_code)
|
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'])
|
||||||
|
|||||||
Reference in New Issue
Block a user