From c4978ba37699d7d29953aff8334c21337582141c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Sat, 28 Nov 2020 15:00:21 +0100 Subject: [PATCH] http response name convention. --- internal/api/members/crud.go | 4 ++-- internal/api/room/broadcast.go | 2 +- internal/api/room/screen.go | 2 +- internal/api/router.go | 2 +- internal/http/auth/auth.go | 6 +++--- internal/utils/http.go | 6 +++--- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/internal/api/members/crud.go b/internal/api/members/crud.go index 228d1d90..fb7649fd 100644 --- a/internal/api/members/crud.go +++ b/internal/api/members/crud.go @@ -30,7 +30,7 @@ func (h *MembersHandler) membersCreate(w http.ResponseWriter, r *http.Request) { id, err := utils.NewUID(32) if err != nil { - utils.HttpInternalServer(w, err) + utils.HttpInternalServerError(w, err) return } @@ -74,7 +74,7 @@ func (h *MembersHandler) membersDelete(w http.ResponseWriter, r *http.Request) { member := GetMember(r) if err := h.sessions.Delete(member.ID()); err != nil { - utils.HttpInternalServer(w, err) + utils.HttpInternalServerError(w, err) return } diff --git a/internal/api/room/broadcast.go b/internal/api/room/broadcast.go index 07f0fa46..de2c72f6 100644 --- a/internal/api/room/broadcast.go +++ b/internal/api/room/broadcast.go @@ -37,7 +37,7 @@ func (h *RoomHandler) boradcastStart(w http.ResponseWriter, r *http.Request) { } if err := h.capture.StartBroadcast(data.URL); err != nil { - utils.HttpInternalServer(w, err) + utils.HttpInternalServerError(w, err) return } diff --git a/internal/api/room/screen.go b/internal/api/room/screen.go index 315c6e76..7afc2117 100644 --- a/internal/api/room/screen.go +++ b/internal/api/room/screen.go @@ -19,7 +19,7 @@ func (h *RoomHandler) screenConfiguration(w http.ResponseWriter, r *http.Request size := h.desktop.GetScreenSize() if size == nil { - utils.HttpInternalServer(w, "Unable to get screen configuration.") + utils.HttpInternalServerError(w, "Unable to get screen configuration.") return } diff --git a/internal/api/router.go b/internal/api/router.go index e828084c..7573d916 100644 --- a/internal/api/router.go +++ b/internal/api/router.go @@ -52,7 +52,7 @@ func (api *ApiManagerCtx) Authenticate(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { session, err := api.sessions.Authenticate(r) if err != nil { - utils.HttpNotAuthenticated(w, err) + utils.HttpUnauthorized(w, err) } else { next.ServeHTTP(w, auth.SetSession(r, session)) } diff --git a/internal/http/auth/auth.go b/internal/http/auth/auth.go index d0a9c3a6..077f8518 100644 --- a/internal/http/auth/auth.go +++ b/internal/http/auth/auth.go @@ -27,7 +27,7 @@ func AdminsOnly(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { session := GetSession(r) if !session.Admin() { - utils.HttpNotAuthorized(w) + utils.HttpForbidden(w) } else { next.ServeHTTP(w, r) } @@ -38,7 +38,7 @@ func HostsOnly(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { session := GetSession(r) if !session.IsHost() { - utils.HttpNotAuthorized(w, "Only host can do this.") + utils.HttpForbidden(w, "Only host can do this.") } else { next.ServeHTTP(w, r) } @@ -49,7 +49,7 @@ func HostsOrAdminsOnly(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { session := GetSession(r) if !session.IsHost() && !session.Admin() { - utils.HttpNotAuthorized(w, "Only host can do this.") + utils.HttpForbidden(w, "Only host can do this.") } else { next.ServeHTTP(w, r) } diff --git a/internal/utils/http.go b/internal/utils/http.go index f520f010..4bf3e611 100644 --- a/internal/utils/http.go +++ b/internal/utils/http.go @@ -50,11 +50,11 @@ func HttpBadRequest(w http.ResponseWriter, res ...interface{}) { defHttpError(w, http.StatusBadRequest, "Bad Request.", res...) } -func HttpNotAuthorized(w http.ResponseWriter, res ...interface{}) { +func HttpUnauthorized(w http.ResponseWriter, res ...interface{}) { defHttpError(w, http.StatusUnauthorized, "Access token does not have the required scope.", res...) } -func HttpNotAuthenticated(w http.ResponseWriter, res ...interface{}) { +func HttpForbidden(w http.ResponseWriter, res ...interface{}) { defHttpError(w, http.StatusForbidden, "Invalid or missing access token.", res...) } @@ -66,7 +66,7 @@ func HttpUnprocessableEntity(w http.ResponseWriter, res ...interface{}) { defHttpError(w, http.StatusUnprocessableEntity, "Unprocessable Entity.", res...) } -func HttpInternalServer(w http.ResponseWriter, res ...interface{}) { +func HttpInternalServerError(w http.ResponseWriter, res ...interface{}) { defHttpError(w, http.StatusInternalServerError, "Internal server error.", res...) }