Skip to content
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

Update README example for accessing headers #40

Merged
merged 1 commit into from
Jul 24, 2020

Conversation

mehyedes
Copy link
Contributor

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

Signed-off-by: Mehdi Yedes mehdi.yedes@gmail.com

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 <mehdi.yedes@gmail.com>
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.

None yet

2 participants