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

notifier: ensure Content-Type header present in webhook notification #1086

Merged
merged 1 commit into from
Oct 8, 2020

Conversation

alecmerdler
Copy link
Contributor

When receiving the notification webhook in Quay, we call Flask's .json() method. This returns None if the Content-Type header is not set to application/json.

Comment on lines 99 to 102
var headers http.Header = map[string][]string{}
headers["Content-Type"] = []string{"application/json"}
for key, val := range d.conf.Headers {
headers[key] = val
}

Copy link
Member

Choose a reason for hiding this comment

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

I think this would be better written as:

Suggested change
var headers http.Header = map[string][]string{}
headers["Content-Type"] = []string{"application/json"}
for key, val := range d.conf.Headers {
headers[key] = val
}
headers := d.conf.Headers.Clone()
headers.Set("Content-Type", "application/json")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What if Headers is nil?

Copy link
Member

Choose a reason for hiding this comment

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

Hm yeah, that eats it because Clone returns nil. We could make Validate ensure it's non-nil, or not do it my suggested way. @ldelossa thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think doing this in Validate method makes sense.

The webhook deliverer will always be sending json data. So in the "Validate()" method, merge any incoming headers with the "Content-type" header and construct the deliverer with the the merged http.Header map.

@alecmerdler alecmerdler force-pushed the webhook-notifier-headers branch 2 times, most recently from 67cd640 to b1c38d2 Compare October 8, 2020 19:16
Signed-off-by: Alec Merdler <alecmerdler@gmail.com>
@alecmerdler alecmerdler force-pushed the webhook-notifier-headers branch from b1c38d2 to 0c1554e Compare October 8, 2020 19:29
@alecmerdler alecmerdler merged commit 06076d6 into quay:main Oct 8, 2020
@alecmerdler alecmerdler deleted the webhook-notifier-headers branch October 8, 2020 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants