Code

Remove query data from the URI path.
[sysdb/webui.git] / server / server.go
index 6b3f8d07a57e5ae715fb828df75cb1f4c556332c..2b0c27e9ce0dc9882c00e2d336516f9c4dfe2f48 100644 (file)
@@ -147,6 +147,9 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
        if len(path) > 0 && path[0] == '/' {
                path = path[1:]
        }
+       if idx := strings.Index(path, "?"); idx != -1 {
+               path = path[:idx]
+       }
        var fields []string
        for _, f := range strings.Split(path, "/") {
                f, err := url.QueryUnescape(f)
@@ -182,19 +185,22 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
                return
        }
        r.ParseForm()
-       page, err := f(req, s)
+       p, err := f(req, s)
        if err != nil {
-               s.badrequest(w, fmt.Errorf("Error: %v", err))
-               return
+               p = &page{
+                       Content: "<section class=\"error\">" +
+                               html(fmt.Sprintf("Error: %v", err)) +
+                               "</section>",
+               }
        }
 
-       page.Query = r.FormValue("query")
-       if page.Title == "" {
-               page.Title = "SysDB - The System Database"
+       p.Query = r.FormValue("query")
+       if p.Title == "" {
+               p.Title = "SysDB - The System Database"
        }
 
        var buf bytes.Buffer
-       err = s.main.Execute(&buf, page)
+       err = s.main.Execute(&buf, p)
        if err != nil {
                s.internal(w, err)
                return