Open platform to collect and prioritize feedback
dont write to body when method is head
goenning0f1eb7b0d358
diff --git a/app/pkg/web/context.go b/app/pkg/web/context.goindex e566a03f6..0ebca912b 100644--- a/app/pkg/web/context.go+++ b/app/pkg/web/context.go@@ -63,7 +63,7 @@ const CookieAuthName = "auth"// CookieSignUpAuthName is the name of the cookie that holds the temporary Authentication Tokenconst CookieSignUpAuthName = "__signup_auth"-//Context shared between http pipeline+// Context shared between http pipelinetype Context struct {context.ContextResponse Response@@ -75,7 +75,7 @@ type Context struct {tasks []worker.Task}-//NewContext creates a new web Context+// NewContext creates a new web Contextfunc NewContext(engine *Engine, req *http.Request, rw http.ResponseWriter, params StringMap) *Context {contextID := rand.String(32)@@ -99,28 +99,28 @@ func NewContext(engine *Engine, req *http.Request, rw http.ResponseWriter, param}}-//Engine returns main HTTP engine+// Engine returns main HTTP enginefunc (c *Context) Engine() *Engine {return c.engine}-//SessionID returns the current session ID+// SessionID returns the current session IDfunc (c *Context) SessionID() string {return c.sessionID}-//SetSessionID sets the session ID on current context+// SetSessionID sets the session ID on current contextfunc (c *Context) SetSessionID(id string) {c.sessionID = idc.Context = log.WithProperty(c.Context, log.PropertyKeySessionID, id)}-//ContextID returns the unique id for this context+// ContextID returns the unique id for this contextfunc (c *Context) ContextID() string {return c.id}-//Commit everything that is pending on current context+// Commit everything that is pending on current contextfunc (c *Context) Commit() error {trx, ok := c.Value(app.TransactionCtxKey).(*dbx.Trx)if ok && trx != nil {@@ -136,7 +136,7 @@ func (c *Context) Commit() error {return nil}-//Rollback everything that is pending on current context+// Rollback everything that is pending on current contextfunc (c *Context) Rollback() {trx, ok := c.Value(app.TransactionCtxKey).(*dbx.Trx)if ok && trx != nil {@@ -144,13 +144,13 @@ func (c *Context) Rollback() {}}-//Enqueue given task to be processed in background+// Enqueue given task to be processed in backgroundfunc (c *Context) Enqueue(task worker.Task) {task.OriginContext = cc.tasks = append(c.tasks, task)}-//Tenant returns current tenant+// Tenant returns current tenantfunc (c *Context) Tenant() *entity.Tenant {tenant, ok := c.Value(app.TenantCtxKey).(*entity.Tenant)if ok {@@ -159,7 +159,7 @@ func (c *Context) Tenant() *entity.Tenant {return nil}-//SetTenant update HTTP context with current tenant+// SetTenant update HTTP context with current tenantfunc (c *Context) SetTenant(tenant *entity.Tenant) {if tenant != nil {c.Set(log.PropertyKeyTenantID, tenant.ID)@@ -168,7 +168,7 @@ func (c *Context) SetTenant(tenant *entity.Tenant) {c.Set(app.TenantCtxKey, tenant)}-//Bind context values into given model+// Bind context values into given modelfunc (c *Context) Bind(i any) error {err := c.engine.binder.Bind(i, c)if err != nil {@@ -177,7 +177,7 @@ func (c *Context) Bind(i any) error {return nil}-//BindTo context values into given model+// BindTo context values into given modelfunc (c *Context) BindTo(i actions.Actionable) *validate.Result {err := c.engine.binder.Bind(i, c)if err != nil {@@ -200,19 +200,19 @@ func (c *Context) BindTo(i actions.Actionable) *validate.Result {return i.Validate(c, c.User())}-//IsAuthenticated returns true if user is authenticated+// IsAuthenticated returns true if user is authenticatedfunc (c *Context) IsAuthenticated() bool {return c.Value(app.UserCtxKey) != nil}-//IsAjax returns true if request is AJAX+// IsAjax returns true if request is AJAXfunc (c *Context) IsAjax() bool {accept := c.Request.GetHeader("Accept")contentType := c.Request.GetHeader("Content-Type")return strings.Contains(accept, JSONContentType) || strings.Contains(contentType, JSONContentType)}-//Unauthorized returns a 401 error response+// Unauthorized returns a 401 error responsefunc (c *Context) Unauthorized() error {if c.IsAjax() {return c.JSON(http.StatusUnauthorized, Map{})@@ -225,7 +225,7 @@ func (c *Context) Unauthorized() error {})}-//Forbidden returns a 403 error response+// Forbidden returns a 403 error responsefunc (c *Context) Forbidden() error {if c.IsAjax() {return c.JSON(http.StatusForbidden, Map{})@@ -238,7 +238,7 @@ func (c *Context) Forbidden() error {})}-//NotFound returns a 404 error page+// NotFound returns a 404 error pagefunc (c *Context) NotFound() error {if c.IsAjax() {return c.JSON(http.StatusNotFound, Map{})@@ -251,7 +251,7 @@ func (c *Context) NotFound() error {})}-//Gone returns a 410 error page+// Gone returns a 410 error pagefunc (c *Context) Gone() error {return c.Page(http.StatusGone, Props{Page: "Error/Error410.page",@@ -260,7 +260,7 @@ func (c *Context) Gone() error {})}-//Failure returns a 500 page+// Failure returns a 500 pagefunc (c *Context) Failure(err error) error {err = errors.StackN(err, 1)cause := errors.Cause(err)@@ -283,7 +283,7 @@ func (c *Context) Failure(err error) error {return err}-//HandleValidation handles given validation result property to return 400 or 500+// HandleValidation handles given validation result property to return 400 or 500func (c *Context) HandleValidation(result *validate.Result) error {if result.Err != nil {return c.Failure(result.Err)@@ -298,24 +298,24 @@ func (c *Context) HandleValidation(result *validate.Result) error {})}-//Attachment returns an attached file+// Attachment returns an attached filefunc (c *Context) Attachment(fileName, contentType string, file []byte) error {c.Response.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", fileName))return c.Blob(http.StatusOK, contentType, file)}-//Ok returns 200 OK with JSON result+// Ok returns 200 OK with JSON resultfunc (c *Context) Ok(data any) error {return c.JSON(http.StatusOK, data)}-//BadRequest returns 400 BadRequest with JSON result+// BadRequest returns 400 BadRequest with JSON resultfunc (c *Context) BadRequest(dict Map) error {return c.JSON(http.StatusBadRequest, dict)}-//Page returns a page with given variables+// Page returns a page with given variablesfunc (c *Context) Page(code int, props Props) error {if c.IsAjax() {return c.JSON(code, Map{})@@ -327,12 +327,12 @@ func (c *Context) Page(code int, props Props) error {return c.Blob(code, UTF8HTMLContentType, buf.Bytes())}-//AddParam add a single param to route parameters list+// AddParam add a single param to route parameters listfunc (c *Context) AddParam(name, value string) {c.params[name] = value}-//User returns authenticated user+// User returns authenticated userfunc (c *Context) User() *entity.User {user, ok := c.Value(app.UserCtxKey).(*entity.User)if ok {@@ -341,7 +341,7 @@ func (c *Context) User() *entity.User {return nil}-//SetUser update HTTP context with current user+// SetUser update HTTP context with current userfunc (c *Context) SetUser(user *entity.User) {if user != nil {c.Context = log.WithProperty(c.Context, log.PropertyKeyUserID, user.ID)@@ -349,7 +349,7 @@ func (c *Context) SetUser(user *entity.User) {c.Set(app.UserCtxKey, user)}-//AddCookie adds a cookie+// AddCookie adds a cookiefunc (c *Context) AddCookie(name, value string, expires time.Time) *http.Cookie {cookie := &http.Cookie{Name: name,@@ -363,7 +363,7 @@ func (c *Context) AddCookie(name, value string, expires time.Time) *http.Cookiereturn cookie}-//RemoveCookie removes a cookie+// RemoveCookie removes a cookiefunc (c *Context) RemoveCookie(name string) {http.SetCookie(&c.Response, &http.Cookie{Name: name,@@ -375,17 +375,17 @@ func (c *Context) RemoveCookie(name string) {})}-//BaseURL returns base URL+// BaseURL returns base URLfunc (c *Context) BaseURL() string {return c.Request.BaseURL()}-//QueryParam returns querystring parameter for given key+// QueryParam returns querystring parameter for given keyfunc (c *Context) QueryParam(key string) string {return c.Request.URL.Query().Get(key)}-//QueryParamAsInt returns querystring parameter for given key+// QueryParamAsInt returns querystring parameter for given keyfunc (c *Context) QueryParamAsInt(key string) (int, error) {value := c.QueryParam(key)if value == "" {@@ -398,7 +398,7 @@ func (c *Context) QueryParamAsInt(key string) (int, error) {return intValue, nil}-//QueryParamAsArray returns querystring parameter for given key as an array+// QueryParamAsArray returns querystring parameter for given key as an arrayfunc (c *Context) QueryParamAsArray(key string) []string {param := c.QueryParam(key)if param != "" {@@ -407,7 +407,7 @@ func (c *Context) QueryParamAsArray(key string) []string {return []string{}}-//Param returns parameter as string+// Param returns parameter as stringfunc (c *Context) Param(name string) string {if c.params == nil {return ""@@ -417,7 +417,7 @@ func (c *Context) Param(name string) string {return strings.TrimLeft(c.params[name], "/")}-//ParamAsInt returns parameter as int+// ParamAsInt returns parameter as intfunc (c *Context) ParamAsInt(name string) (int, error) {value := c.Param(name)intValue, err := strconv.Atoi(value)@@ -427,7 +427,7 @@ func (c *Context) ParamAsInt(name string) (int, error) {return intValue, nil}-//GetMatchedRoutePath returns the Matched Route name+// GetMatchedRoutePath returns the Matched Route namefunc (c *Context) GetMatchedRoutePath() string {return "/" + c.Param(httprouter.MatchedRoutePathParam)}@@ -473,6 +473,11 @@ func (c *Context) Blob(code int, contentType string, b []byte) error {c.Response.Header().Set("Content-Type", contentType)c.Response.WriteHeader(code)+ // Don't write any body for HEAD requests+ if c.Request.Method == http.MethodHead {+ return nil+ }+_, err := c.Response.Write(b)if err != nil {return errors.Wrap(err, "failed to write response")@@ -528,7 +533,7 @@ func (c *Context) SetCanonicalURL(rawurl string) {}}-//TenantBaseURL returns base URL for a given tenant+// TenantBaseURL returns base URL for a given tenantfunc TenantBaseURL(ctx context.Context, tenant *entity.Tenant) string {if env.IsSingleHostMode() {return BaseURL(ctx)