Skip to content

Case insensitive lookup of header values in http proxy events #185

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

Closed
michaelbrewer opened this issue Sep 30, 2020 · 0 comments
Closed

Case insensitive lookup of header values in http proxy events #185

michaelbrewer opened this issue Sep 30, 2020 · 0 comments
Labels
feature-request feature request

Comments

@michaelbrewer
Copy link
Contributor

michaelbrewer commented Sep 30, 2020

Is your feature request related to a problem? Please describe.

Http headers are meant to be case insensitive, but lambda events use case sensitive dicts for the header keys.

For example getting the Authorization header you will need to do a case insensitive look up to support if the header is authorization. So you end up doing something like this.

authorization = None
for key, value in self.headers.items():
    if name.lower() == 'authorization'
        authorization = value

Describe the solution you'd like

Linked pull request : #185

Update BaseProxyEvent.get_header_value method to support case insensitive lookups by default

authorization = event.get_header_value("authorization")
    def get_header_value(
        self, name: str, default_value: Optional[str] = None, case_sensitive: Optional[bool] = False
    ) -> Optional[str]:
        """Get header value by name

        Parameters
        ----------
        name: str
            Header name
        default_value: str, optional
            Default value if no value was found by name
        case_sensitive: bool
            Whether to use a case sensitive look up
        Returns
        -------
        str, optional
            Header value
        """
        if case_sensitive:
            return self.headers.get(name, default_value)
        
        return next((value for key, value in self.headers.items() if name.lower() == key.lower()), default_value)

Questions

  • Should we default to case insensitive look ups? This is what most people would want?
  • Just return the first match? Or support returning all matches?

Describe alternatives you've considered

Use the requests CaseInsensitiveDict or port it :

Additional context

From the Http 1.1 spec, https headers are not supposed to be case sensitive: https://www.w3.org/Protocols/rfc2616/rfc2616.html

@michaelbrewer michaelbrewer added feature-request feature request triage Pending triage from maintainers labels Sep 30, 2020
@michaelbrewer michaelbrewer changed the title Case insensitive lookup of header values in http proxy events Case insensitive lookup of header values in http proxy events [RFC] Sep 30, 2020
@michaelbrewer michaelbrewer changed the title Case insensitive lookup of header values in http proxy events [RFC] Case insensitive lookup of header values in http proxy events Oct 1, 2020
@heitorlessa heitorlessa removed the triage Pending triage from maintainers label Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request feature request
Projects
Development

No branches or pull requests

2 participants