Found while fixing #123, out of that issue's scope.
renderTemplate now buffers, so a mid-render failure never ships a partial body and can serve a real 500. Five call sites defeat the status half of that, because they call w.WriteHeader before renderTemplate:
internal/handlers/auth.gorenderLoginError
internal/handlers/source_management.go, four form-validation branches (missing name, bad retention on create, and the two matching branches on edit)
On those paths the status is already committed when rendering starts, so a template failure yields the pre-set 400 with an Internal server error body rather than a 500. The body is honest and carries no part of the aborted page; only the status is wrong.
Severity is low: it only shows up when a form-error page's own template fails. The fix is to let the render path carry the intended status and write the header after a successful render, e.g. a renderTemplateStatus(w, r, page, data, status) variant that the plain helper delegates to with 200.
Definition of done
No handler calls WriteHeader before renderTemplate.
A form-error page still responds 400 with its rendered body.
A failing template on a form-error path responds 500 with no partial body.
Found while fixing https://git.eeqj.de/sneak/webhooker/issues/123, out of that issue's scope.
`renderTemplate` now buffers, so a mid-render failure never ships a partial body and can serve a real 500. Five call sites defeat the status half of that, because they call `w.WriteHeader` before `renderTemplate`:
- `internal/handlers/auth.go` `renderLoginError`
- `internal/handlers/source_management.go`, four form-validation branches (missing name, bad retention on create, and the two matching branches on edit)
On those paths the status is already committed when rendering starts, so a template failure yields the pre-set 400 with an `Internal server error` body rather than a 500. The body is honest and carries no part of the aborted page; only the status is wrong.
Severity is low: it only shows up when a form-error page's own template fails. The fix is to let the render path carry the intended status and write the header after a successful render, e.g. a `renderTemplateStatus(w, r, page, data, status)` variant that the plain helper delegates to with 200.
## Definition of done
- No handler calls `WriteHeader` before `renderTemplate`.
- A form-error page still responds 400 with its rendered body.
- A failing template on a form-error path responds 500 with no partial body.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Found while fixing #123, out of that issue's scope.
renderTemplatenow buffers, so a mid-render failure never ships a partial body and can serve a real 500. Five call sites defeat the status half of that, because they callw.WriteHeaderbeforerenderTemplate:internal/handlers/auth.gorenderLoginErrorinternal/handlers/source_management.go, four form-validation branches (missing name, bad retention on create, and the two matching branches on edit)On those paths the status is already committed when rendering starts, so a template failure yields the pre-set 400 with an
Internal server errorbody rather than a 500. The body is honest and carries no part of the aborted page; only the status is wrong.Severity is low: it only shows up when a form-error page's own template fails. The fix is to let the render path carry the intended status and write the header after a successful render, e.g. a
renderTemplateStatus(w, r, page, data, status)variant that the plain helper delegates to with 200.Definition of done
WriteHeaderbeforerenderTemplate.