chore(server): replace 404 with 401 for unsupported routes and methods
This commit is contained in:
@@ -32,10 +32,10 @@ func (h *dnsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
case http.MethodPut:
|
||||
h.setStatus(w, r)
|
||||
default:
|
||||
http.Error(w, "", http.StatusNotFound)
|
||||
http.Error(w, "method "+r.Method+" not supported", http.StatusBadRequest)
|
||||
}
|
||||
default:
|
||||
http.Error(w, "", http.StatusNotFound)
|
||||
http.Error(w, "route "+r.RequestURI+" not supported", http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ type handlerV0 struct {
|
||||
|
||||
func (h *handlerV0) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
http.Error(w, "unversioned API: only supports GET method", http.StatusNotFound)
|
||||
http.Error(w, "unversioned API: only supports GET method", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
switch r.RequestURI {
|
||||
@@ -63,6 +63,6 @@ func (h *handlerV0) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
h.logger.Warn(err.Error())
|
||||
}
|
||||
default:
|
||||
http.Error(w, "unversioned API: requested URI not found", http.StatusNotFound)
|
||||
http.Error(w, "unversioned API: requested URI not found", http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ func (h *handlerV1) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
h.publicip.ServeHTTP(w, r)
|
||||
default:
|
||||
errString := fmt.Sprintf("%s %s not found", r.Method, r.RequestURI)
|
||||
http.Error(w, errString, http.StatusNotFound)
|
||||
http.Error(w, errString, http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,24 +34,24 @@ func (h *openvpnHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
case http.MethodPut:
|
||||
h.setStatus(w, r)
|
||||
default:
|
||||
http.Error(w, "", http.StatusNotFound)
|
||||
http.Error(w, "method "+r.Method+" not supported", http.StatusBadRequest)
|
||||
}
|
||||
case "/settings":
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
h.getSettings(w)
|
||||
default:
|
||||
http.Error(w, "", http.StatusNotFound)
|
||||
http.Error(w, "method "+r.Method+" not supported", http.StatusBadRequest)
|
||||
}
|
||||
case "/portforwarded":
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
h.getPortForwarded(w)
|
||||
default:
|
||||
http.Error(w, "", http.StatusNotFound)
|
||||
http.Error(w, "method "+r.Method+" not supported", http.StatusBadRequest)
|
||||
}
|
||||
default:
|
||||
http.Error(w, "", http.StatusNotFound)
|
||||
http.Error(w, "route "+r.RequestURI+" not supported", http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,10 +26,10 @@ func (h *publicIPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
case http.MethodGet:
|
||||
h.getPublicIP(w)
|
||||
default:
|
||||
http.Error(w, "", http.StatusNotFound)
|
||||
http.Error(w, "method "+r.Method+" not supported", http.StatusBadRequest)
|
||||
}
|
||||
default:
|
||||
http.Error(w, "", http.StatusNotFound)
|
||||
http.Error(w, "route "+r.RequestURI+" not supported", http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,10 +44,10 @@ func (h *updaterHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
case http.MethodPut:
|
||||
h.setStatus(w, r)
|
||||
default:
|
||||
http.Error(w, "", http.StatusNotFound)
|
||||
http.Error(w, "method "+r.Method+" not supported", http.StatusBadRequest)
|
||||
}
|
||||
default:
|
||||
http.Error(w, "", http.StatusNotFound)
|
||||
http.Error(w, "route "+r.RequestURI+" not supported", http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user