-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Conversation
notifier/webhook/deliverer.go
Outdated
var headers http.Header = map[string][]string{} | ||
headers["Content-Type"] = []string{"application/json"} | ||
for key, val := range d.conf.Headers { | ||
headers[key] = val | ||
} | ||
|
There was a problem hiding this comment.
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:
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") | |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
67cd640
to
b1c38d2
Compare
Signed-off-by: Alec Merdler <alecmerdler@gmail.com>
b1c38d2
to
0c1554e
Compare
When receiving the notification webhook in Quay, we call Flask's
.json()
method. This returnsNone
if theContent-Type
header is not set toapplication/json
.