diff options
author | Ben Morrison <ben@gbmor.dev> | 2019-05-20 03:12:51 -0400 |
---|---|---|
committer | Ben Morrison <ben@gbmor.dev> | 2019-05-20 03:12:51 -0400 |
commit | b6e7bb3cee897688300cacf29291ee11751fe78c (patch) | |
tree | e77d8a2beab96a03f24959a6c26f6254e32ae045 | |
parent | 3e8842fd2937466758ad93c887fab23274b7a701 (diff) | |
download | getwtxt-b6e7bb3cee897688300cacf29291ee11751fe78c.tar.gz |
error handling after http.Request.ParseForm()
-rw-r--r-- | http.go | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/http.go b/http.go index b338796..b348604 100644 --- a/http.go +++ b/http.go @@ -111,18 +111,23 @@ func apiEndpointHandler(w http.ResponseWriter, r *http.Request) { uip := getIPFromCtx(r.Context()) log.Printf("Request from %v :: %v %v\n", uip, r.Method, r.URL) - if r.FormValue("q") != "" || r.FormValue("url") != "" { + err := r.ParseForm() + if err == nil && (r.FormValue("q") != "" || r.FormValue("url") != "") { apiEndpointQuery(w, r) return + } else if err != nil { + log.Printf("Error parsing query from %v :: %v %v :: %v\n", uip, r.Method, r.URL, err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return } w.Header().Set("Content-Type", htmlutf8) + n, err := w.Write([]byte(r.URL.String())) if err != nil || n == 0 { log.Printf("500: Error writing to HTTP stream: %v, %v %v via %v\n", err, r.Method, r.URL, uip) http.Error(w, err.Error(), http.StatusInternalServerError) } - } // handles POST for "/api/plain/users" |