Closed mehyedes closed 4 years ago
Updated README example for accessing the headers with the python3-http template
python3-http
Signed-off-by: Mehdi Yedes mehdi.yedes@gmail.com
Using event.headers['Some-Header'] throws an error when calling a python3-http function if the header is not set. So it is better to use event.headers.get('Some-Header') instead.
event.headers['Some-Header']
event.headers.get('Some-Header')
After deploying this small function
def handle(event, context): header = event.headers.get('Test-Header') return { "statusCode": 200, "body": { "Header received": header } }
The function would not fail, but only return null when the header Test-Header is not set
null
Test-Header
$ curl 127.0.0.1:8080/function/python-test -H "Test-Header: testtest" {"Header received":"testtest"} $ curl 127.0.0.1:8080/function/python-test {"Header received":null}
git commit -s
Updated README example for accessing the headers with the
python3-http
templateSigned-off-by: Mehdi Yedes mehdi.yedes@gmail.com
Description
Motivation and Context
Using
event.headers['Some-Header']
throws an error when calling apython3-http
function if the header is not set. So it is better to useevent.headers.get('Some-Header')
instead.How Has This Been Tested?
After deploying this small function
The function would not fail, but only return
null
when the headerTest-Header
is not setTypes of changes
Checklist:
git commit -s