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

fix(event_handlers): omit explicit None HTTP header values #1793

Merged

Conversation

leandrodamascena
Copy link
Contributor

Issue number: #1791

Summary

Changes

Add a fix for when header is None and avoid iterator or len issues

User experience

Although not recommended by the RFC that defines headers in the HTTP protocol, the user can force a header with a value of None. To avoid this problem the header which has value None will be omitted from the response

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@leandrodamascena leandrodamascena requested a review from a team as a code owner December 20, 2022 22:56
@leandrodamascena leandrodamascena requested review from heitorlessa and removed request for a team December 20, 2022 22:56
@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Dec 20, 2022
@github-actions github-actions bot added the bug Something isn't working label Dec 20, 2022
@@ -65,8 +66,9 @@ def serialize(self, headers: Dict[str, Union[str, List[str]]], cookies: List[Coo
if isinstance(values, str):
payload[key].append(values)
else:
for value in values:
payload[key].append(value)
if values:
Copy link
Contributor

Choose a reason for hiding this comment

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

when you accept a falsy value but not null, check for null otherwise a X-Is-Admin: false will be omitted here. For example, if values is None, would work in both cases.

payload[key].append(value)
if values:
for value in values:
payload[key].append(value)
Copy link
Contributor

Choose a reason for hiding this comment

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

we can drop an additional for loop by using list.extend, as it accepts an Iterable and it'll add all elements at the end of the list. This drops the complexity

@heitorlessa
Copy link
Contributor

Last missing piece is docs. We should mention somewhere that custom headers with None value will be omitted. Pre-approving

@codecov-commenter
Copy link

codecov-commenter commented Dec 21, 2022

Codecov Report

Base: 97.58% // Head: 97.58% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (b886504) compared to base (409ced2).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #1793   +/-   ##
========================================
  Coverage    97.58%   97.58%           
========================================
  Files          141      141           
  Lines         6420     6425    +5     
  Branches       440      442    +2     
========================================
+ Hits          6265     6270    +5     
  Misses         123      123           
  Partials        32       32           
Impacted Files Coverage Δ
aws_lambda_powertools/shared/headers_serializer.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@heitorlessa heitorlessa changed the title fix(headers-serializer): skiping none values fix(event_handlers): omit explicit null HTTP header values Dec 21, 2022
@heitorlessa heitorlessa changed the title fix(event_handlers): omit explicit null HTTP header values fix(event_handlers): omit explicit None HTTP header values Dec 21, 2022
@leandrodamascena leandrodamascena merged commit e9aacfb into aws-powertools:develop Dec 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working commons size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants