Skip to content

Commit

Permalink
tornado_requests: set Content-Type header correctly for JSON
Browse files Browse the repository at this point in the history
Dumping the data first to a string caused the Content-Type header to be set
to application/x-www-form-urlencoded. Now if the request function gets a
dict, it is converted to a JSON string and the Content-Type header is set
to application/json.

Signed-off-by: Thore Sommer <mail@thson.de>
  • Loading branch information
THS-on committed Jan 24, 2022
1 parent 1c5bb70 commit 4cfadda
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 1 addition & 2 deletions keylime/cloud_verifier_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,7 @@ def prepare_v(agent):
post_data = {
'encrypted_key': b64_encrypted_V
}
v_json_message = json.dumps(post_data)
return v_json_message
return post_data


def prepare_get_quote(agent):
Expand Down
10 changes: 10 additions & 0 deletions keylime/tornado_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

from tornado import httpclient

from keylime import json


async def request(method, url, params=None, data=None, context=None, headers=None):

Expand All @@ -20,6 +22,14 @@ async def request(method, url, params=None, data=None, context=None, headers=Non
if context is not None:
url = url.replace('http://', 'https://', 1)

# Convert dict to JSON before sending
if isinstance(data, dict):
data = json.dumps(data)
if headers is None:
headers = {}
if "Content-Type" not in headers:
headers["Content-Type"] = "application/json"

try:
req = httpclient.HTTPRequest(url=url,
method=method,
Expand Down

0 comments on commit 4cfadda

Please sign in to comment.