-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add raw body support to python3 templates #207
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,15 @@ | |
# Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
import sys | ||
import os | ||
from function import handler | ||
|
||
|
||
# distutils.util.strtobool() can throw an exception | ||
def is_true(val): | ||
return val and val.lower() == "true" or val == "1" | ||
|
||
|
||
def get_stdin(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would guess that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to see a test that verifies the input received in the function is a perfect match for the bytes inputted. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you accept the data in from a HTTP request ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have updated this PR and tested with image data and it is working fine. Image file written in container is rendering correctly. |
||
buf = "" | ||
while(True): | ||
|
@@ -14,8 +21,14 @@ def get_stdin(): | |
break | ||
return buf | ||
|
||
|
||
if __name__ == "__main__": | ||
st = get_stdin() | ||
raw_body = os.getenv("RAW_BODY") | ||
|
||
if is_true(raw_body): | ||
st = st.encode("utf-8", "surrogateescape") | ||
|
||
ret = handler.handle(st) | ||
if ret != None: | ||
print(ret) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A complete sentence for the doc string would be better, it is clear to me because i recommended strtobool, but a future contributor won't have the context
if you want to use strtobool, you could also do this
but either method is good to me 👍