[MM-25677] Content-Type is optional (#14705)
* Content-Type is optional mime.ParseMimeType returns and "no media type" error if the passed string is empty. Given that the Content-Type header is optional we shouldn't return an error in that case, so we're fixing that allowing the users to call the webhook without passing that header * Include webhook id in the error message Given that the number of webhooks could be big the user could need the id to check which one of the multiple webhooks are failing so include the id aids in that part
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
6643a7c610
Коммит
beadeaf8b5
@@ -28,11 +28,22 @@ func incomingWebhook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
|
||||
var err *model.AppError
|
||||
var mediaType string
|
||||
incomingWebhookPayload := &model.IncomingWebhookRequest{}
|
||||
mediaType, _, mimeErr := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
||||
if mimeErr != nil && mimeErr != mime.ErrInvalidMediaParameter {
|
||||
c.Err = model.NewAppError("incomingWebhook", "api.webhook.incoming.error", nil, mimeErr.Error(), http.StatusBadRequest)
|
||||
return
|
||||
contentType := r.Header.Get("Content-Type")
|
||||
// Content-Type header is optional so could be empty
|
||||
if contentType != "" {
|
||||
var mimeErr error
|
||||
mediaType, _, mimeErr = mime.ParseMediaType(contentType)
|
||||
if mimeErr != nil && mimeErr != mime.ErrInvalidMediaParameter {
|
||||
c.Err = model.NewAppError("incomingWebhook",
|
||||
"api.webhook.incoming.error",
|
||||
nil,
|
||||
"webhook_id="+id+", error: "+mimeErr.Error(),
|
||||
http.StatusBadRequest,
|
||||
)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
defer func() {
|
||||
@@ -58,7 +69,12 @@ func incomingWebhook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
err := decoder.Decode(incomingWebhookPayload, r.PostForm)
|
||||
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("incomingWebhook", "api.webhook.incoming.error", nil, err.Error(), http.StatusBadRequest)
|
||||
c.Err = model.NewAppError("incomingWebhook",
|
||||
"api.webhook.incoming.error",
|
||||
nil,
|
||||
"webhook_id="+id+", error: "+err.Error(),
|
||||
http.StatusBadRequest,
|
||||
)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
|
||||
Ссылка в новой задаче
Block a user