Use http.StatusContinue constant instead of magic number 100

Replace magic number `100` with `http.StatusContinue` constant for better code clarity and maintainability in `bodyAllowedForStatus` function.

Fixes #4489
This commit is contained in:
mehrdadbn9 2026-02-06 15:29:32 +03:30
parent d7776de7d4
commit f4f12eaee2
2 changed files with 3 additions and 1 deletions

View File

@ -1056,9 +1056,10 @@ func (c *Context) requestHeader(key string) string {
/************************************/ /************************************/
// bodyAllowedForStatus is a copy of http.bodyAllowedForStatus non-exported function. // bodyAllowedForStatus is a copy of http.bodyAllowedForStatus non-exported function.
// Use http.StatusContinue constant for better code clarity
func bodyAllowedForStatus(status int) bool { func bodyAllowedForStatus(status int) bool {
switch { switch {
case status >= 100 && status <= 199: case status >= http.StatusContinue && status <= 199:
return false return false
case status == http.StatusNoContent: case status == http.StatusNoContent:
return false return false

View File

@ -1033,6 +1033,7 @@ func TestContextGetCookie(t *testing.T) {
func TestContextBodyAllowedForStatus(t *testing.T) { func TestContextBodyAllowedForStatus(t *testing.T) {
assert.False(t, bodyAllowedForStatus(http.StatusProcessing)) assert.False(t, bodyAllowedForStatus(http.StatusProcessing))
assert.False(t, bodyAllowedForStatus(http.StatusNoContent)) assert.False(t, bodyAllowedForStatus(http.StatusNoContent))
assert.False(t, bodyAllowedForStatus(http.StatusContinue))
assert.False(t, bodyAllowedForStatus(http.StatusNotModified)) assert.False(t, bodyAllowedForStatus(http.StatusNotModified))
assert.True(t, bodyAllowedForStatus(http.StatusInternalServerError)) assert.True(t, bodyAllowedForStatus(http.StatusInternalServerError))
} }