Skip to content

Commit

Permalink
Add Drop method to DefaultCtx for closing connections
Browse files Browse the repository at this point in the history
The Drop method allows closing connections without sending a response, improving control over connection handling. Also updated a test assertion to use StatusOK for improved readability and consistency.
  • Loading branch information
ryanbekhen committed Dec 21, 2024
1 parent ccc60f6 commit 4137cb3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -1979,6 +1979,7 @@ func (c *DefaultCtx) setRoute(route *Route) {
c.route = route
}

// Drop closes the connection without sending a response.
func (c *DefaultCtx) Drop() error {
//nolint:wrapcheck // This must not be wrapped
return c.RequestCtx().Conn().Close()
Expand Down
2 changes: 1 addition & 1 deletion ctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5872,7 +5872,7 @@ func Test_Ctx_Drop(t *testing.T) {
resp, err = app.Test(httptest.NewRequest(MethodGet, "/no-response", nil))
require.NoError(t, err)
require.NotNil(t, resp)
require.Equal(t, 200, resp.StatusCode)
require.Equal(t, StatusOK, resp.StatusCode)
require.Equal(t, "0", resp.Header.Get("Content-Length"))
}

Expand Down

0 comments on commit 4137cb3

Please sign in to comment.