Skip to content

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

Closed
@michaelbrewer

Description

@michaelbrewer

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions