Skip to content

Commit 7438288

Browse files
authored
Updating to newer JSON protocol (#10)
1 parent 9392d73 commit 7438288

2 files changed

Lines changed: 22 additions & 11 deletions

File tree

fdk/json/request.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ def readline(stream):
4747
elif c == "}" and ret:
4848
line += c
4949
s = line.replace('\n"\n,', '",').replace("\n}", "}")
50+
# due to weird padding we omit last 4 bytes: \n}\n\n
51+
stream.read(4)
52+
s += "}"
5053
print("Before JSON parsing: {}".format(s),
5154
file=sys.stderr, flush=True)
5255
return ujson.loads(s)

fdk/tests/data.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,22 @@
4444
\r\n{"media_url": "http://localhost:8080/img.png"}
4545
"""
4646

47-
json_request_with_data = ('{"body":"{\\"a\\":\\"a\\"}\n"\n'
48-
',"headers":{"Content-Type":["application/json"],'
49-
'"Host":["localhost:8080"],'
50-
'"User-Agent":["curl/7.51.0"]}'
51-
'\n}')
52-
53-
json_request_without_data = ('{"body":""\n'
54-
',"headers":{"Content-Type":["application/json"],'
55-
'"Host":["localhost:8080"],'
56-
'"User-Agent":["curl/7.51.0"]}'
57-
'\n}')
47+
json_request_with_data = (
48+
'{\n"call_id":"some_id"\n,'
49+
'"content_type":"application/json"\n'
50+
',"body":"{\\"a\\":\\"a\\"}\n"\n'
51+
',"protocol":{"type":"json"\n'
52+
',"request_url":"/v1/apps?something=something&etc=etc"\n'
53+
',"headers":{"Content-Type":["application/json"],'
54+
'"Host":["localhost:8080"],"User-Agent":["curl/7.51.0"]}\n'
55+
'\n}\n\n')
56+
57+
json_request_without_data = (
58+
'{\n"call_id":"some_id"\n,'
59+
'"content_type":"application/json"\n'
60+
',"body":""\n'
61+
',"protocol":{"type":"json"\n'
62+
',"request_url":"/v1/apps?something=something&etc=etc"\n'
63+
',"headers":{"Content-Type":["application/json"],'
64+
'"Host":["localhost:8080"],"User-Agent":["curl/7.51.0"]}\n'
65+
'\n}\n\n')

0 commit comments

Comments
 (0)