Skip to content

Conversation

@mehyedes
Copy link
Contributor

Updated README example for accessing the headers with the python3-http template

Signed-off-by: Mehdi Yedes [email protected]

Description

Motivation and Context

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.

How Has This Been Tested?

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

$ 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}

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I've read the CONTRIBUTION guide
  • I have signed-off my commits with git commit -s
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Using event.headers['Some-Header'] throws an error when the header is
not set. So it is better to use event.headers.get('Some-Header')
instead.

Signed-off-by: Mehdi Yedes <[email protected]>
Copy link
Member

@alexellis alexellis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@alexellis alexellis merged commit d4f9645 into openfaas:master Jul 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants