From 5f853d8abab3b726ae629b7c1ee5581f90c065b4 Mon Sep 17 00:00:00 2001 From: Kevin Le Brun Date: Sun, 29 Mar 2015 19:58:38 +0200 Subject: [PATCH] Allow charset to be defined in Content-Type header The payload couldn't be parsed when charset was present in the `Content-Type` header. The content type should begin with the MIME type so we now check if the content type starts with `application/json` or `application/x-www-form-urlencoded`. This closes #20 --- webhook.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webhook.go b/webhook.go index 6398ad6..e9f69da 100644 --- a/webhook.go +++ b/webhook.go @@ -152,7 +152,7 @@ func hookHandler(w http.ResponseWriter, r *http.Request) { contentType := r.Header.Get("Content-Type") - if contentType == "application/json" { + if strings.HasPrefix(contentType, "application/json") { decoder := json.NewDecoder(strings.NewReader(string(body))) decoder.UseNumber() @@ -161,7 +161,7 @@ func hookHandler(w http.ResponseWriter, r *http.Request) { if err != nil { log.Printf("error parsing JSON payload %+v\n", err) } - } else if contentType == "application/x-www-form-urlencoded" { + } else if strings.HasPrefix(contentType, "application/x-www-form-urlencoded") { fd, err := url.ParseQuery(string(body)) if err != nil { log.Printf("error parsing form payload %+v\n", err)