summary refs log tree commit diff stats
path: root/http.go
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-05-20 03:12:51 -0400
committerBen Morrison <ben@gbmor.dev>2019-05-20 03:12:51 -0400
commitb6e7bb3cee897688300cacf29291ee11751fe78c (patch)
treee77d8a2beab96a03f24959a6c26f6254e32ae045 /http.go
parent3e8842fd2937466758ad93c887fab23274b7a701 (diff)
downloadgetwtxt-b6e7bb3cee897688300cacf29291ee11751fe78c.tar.gz
error handling after http.Request.ParseForm()
Diffstat (limited to 'http.go')
-rw-r--r--http.go9
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"