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:
|
case http.MethodPut:
|
||||||
h.setStatus(w, r)
|
h.setStatus(w, r)
|
||||||
default:
|
default:
|
||||||
http.Error(w, "", http.StatusNotFound)
|
http.Error(w, "method "+r.Method+" not supported", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
default:
|
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) {
|
func (h *handlerV0) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method != http.MethodGet {
|
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
|
return
|
||||||
}
|
}
|
||||||
switch r.RequestURI {
|
switch r.RequestURI {
|
||||||
@@ -63,6 +63,6 @@ func (h *handlerV0) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
h.logger.Warn(err.Error())
|
h.logger.Warn(err.Error())
|
||||||
}
|
}
|
||||||
default:
|
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)
|
h.publicip.ServeHTTP(w, r)
|
||||||
default:
|
default:
|
||||||
errString := fmt.Sprintf("%s %s not found", r.Method, r.RequestURI)
|
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:
|
case http.MethodPut:
|
||||||
h.setStatus(w, r)
|
h.setStatus(w, r)
|
||||||
default:
|
default:
|
||||||
http.Error(w, "", http.StatusNotFound)
|
http.Error(w, "method "+r.Method+" not supported", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
case "/settings":
|
case "/settings":
|
||||||
switch r.Method {
|
switch r.Method {
|
||||||
case http.MethodGet:
|
case http.MethodGet:
|
||||||
h.getSettings(w)
|
h.getSettings(w)
|
||||||
default:
|
default:
|
||||||
http.Error(w, "", http.StatusNotFound)
|
http.Error(w, "method "+r.Method+" not supported", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
case "/portforwarded":
|
case "/portforwarded":
|
||||||
switch r.Method {
|
switch r.Method {
|
||||||
case http.MethodGet:
|
case http.MethodGet:
|
||||||
h.getPortForwarded(w)
|
h.getPortForwarded(w)
|
||||||
default:
|
default:
|
||||||
http.Error(w, "", http.StatusNotFound)
|
http.Error(w, "method "+r.Method+" not supported", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
default:
|
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:
|
case http.MethodGet:
|
||||||
h.getPublicIP(w)
|
h.getPublicIP(w)
|
||||||
default:
|
default:
|
||||||
http.Error(w, "", http.StatusNotFound)
|
http.Error(w, "method "+r.Method+" not supported", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
default:
|
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:
|
case http.MethodPut:
|
||||||
h.setStatus(w, r)
|
h.setStatus(w, r)
|
||||||
default:
|
default:
|
||||||
http.Error(w, "", http.StatusNotFound)
|
http.Error(w, "method "+r.Method+" not supported", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
http.Error(w, "", http.StatusNotFound)
|
http.Error(w, "route "+r.RequestURI+" not supported", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user