Skip to content

Authorizer Event Cookies is always empty #507

Open
@weaverjess

Description

@weaverjess

https://pkg.go.dev/github.com/aws/aws-lambda-go/events@v1.40.0#APIGatewayV2CustomAuthorizerV2Request.Cookies

I am unable to get the Cookies portion to populate in the AuthorizerV2Request object.

I am able to see cookies under the cookie Header, but the Cookies object itself seems to have no function.

Activity

changed the title [-]event Cookies is always empty[/-] [+]Authorizer Event Cookies is always empty[/+] on Apr 26, 2023
weaverjess

weaverjess commented on Apr 27, 2023

@weaverjess
Author

While HTTP Headers are case-insensitive, I've heard that casing can be an issue with API GW... not sure if that is what is going on, but effectively right now I am doing something like the below to just get a slice of native http.Cookie to work with.

func ParseCookies(headers map[string]string) []*http.Cookie {
	header := http.Header{}

	val, ok := headers["Cookie"]
	if ok {
		header.Add("Cookie", val)
	}

	val, ok = headers["cookie"]
	if ok {
		header.Add("Cookie", val)
	}

	request := http.Request{Header: header}

	return request.Cookies()
}

I think though it would be event better if the event exposed a "GetCookie" method, something like:

func GetCookie(headers map[string]string, cookieName string) (*http.Cookie, error) {
	header := http.Header{}

	val, ok := headers["Cookie"]
	if ok {
		header.Add("Cookie", val)
	}

	val, ok = headers["cookie"]
	if ok {
		header.Add("Cookie", val)
	}

	request := http.Request{Header: header}

	return request.Cookie(cookieName)
}

Which could be used to try and get a cookie, or idiomatically an error

added
type/eventsissue or feature request related to the events package
on Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/eventsissue or feature request related to the events package

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Authorizer Event Cookies is always empty · Issue #507 · aws/aws-lambda-go