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

Authorizer Event Cookies is always empty #507

Open
weaverjess opened this issue Apr 26, 2023 · 1 comment
Open

Authorizer Event Cookies is always empty #507

weaverjess opened this issue Apr 26, 2023 · 1 comment
Labels
type/events issue or feature request related to the events package

Comments

@weaverjess
Copy link

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.

@weaverjess weaverjess changed the title event Cookies is always empty Authorizer Event Cookies is always empty Apr 26, 2023
@weaverjess
Copy link
Author

weaverjess commented Apr 27, 2023

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

@bmoffatt bmoffatt added the type/events issue or feature request related to the events package label Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/events issue or feature request related to the events package
Projects
None yet
Development

No branches or pull requests

2 participants