Skip to content

fix(test): properly verify deferred header flushing for non-WebSocket responses#272

Merged
fzipi merged 4 commits intofix/websocketsfrom
copilot/sub-pr-262
Mar 20, 2026
Merged

fix(test): properly verify deferred header flushing for non-WebSocket responses#272
fzipi merged 4 commits intofix/websocketsfrom
copilot/sub-pr-262

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 12, 2026

TestNonWebSocketResponseDoesNotFlushImmediately was asserting rec.Code == 200, but httptest.ResponseRecorder.Code defaults to 200 regardless of whether WriteHeader was ever called — making the assertion vacuously true.

Changes

  • New writeHeaderTracker helper: wraps httptest.ResponseRecorder and sets a writeHeaderCalled bool when WriteHeader is actually invoked on the underlying writer
  • Updated test assertion: replaced require.Equal(t, http.StatusOK, rec.Code) with require.False(t, rec.writeHeaderCalled) — directly verifying the interceptor defers the header flush
type writeHeaderTracker struct {
    *httptest.ResponseRecorder
    writeHeaderCalled bool
}

func (w *writeHeaderTracker) WriteHeader(code int) {
    w.writeHeaderCalled = true
    w.ResponseRecorder.WriteHeader(code)
}

📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Co-authored-by: fzipi <3012076+fzipi@users.noreply.github.com>
Copilot AI changed the title [WIP] [WIP] Address feedback on WebSocket support when WAF is active fix(test): properly verify deferred header flushing for non-WebSocket responses Mar 12, 2026
Copilot AI requested a review from fzipi March 12, 2026 22:42
@fzipi fzipi marked this pull request as ready for review March 13, 2026 13:11
@fzipi
Copy link
Copy Markdown
Member

fzipi commented Mar 13, 2026

Co-authored-by: fzipi <3012076+fzipi@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 13, 2026

@copilot fix the lint step in https://github.com/corazawaf/coraza-caddy/actions/runs/23027297918/job/66956554479?pr=272

Fixed in c926a7e. The two errcheck lint failures were in TestRegularRequestStillProcessesResponseBody — added error checking for tx.ProcessRequestBody() and wrapped.Write(...).

Copilot AI requested a review from fzipi March 13, 2026 19:19
@fzipi fzipi merged commit f87db9d into fix/websockets Mar 20, 2026
3 checks passed
@fzipi fzipi deleted the copilot/sub-pr-262 branch March 20, 2026 21:48
fzipi added a commit that referenced this pull request Apr 12, 2026
… responses (#272)

* Initial plan

* fix(test): use writeHeaderTracker to properly verify deferred flushing

Co-authored-by: fzipi <3012076+fzipi@users.noreply.github.com>

* fix(lint): check error return values for ProcessRequestBody and Write

Co-authored-by: fzipi <3012076+fzipi@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: fzipi <3012076+fzipi@users.noreply.github.com>
fzipi added a commit that referenced this pull request Apr 14, 2026
… responses (#272)

* Initial plan

* fix(test): use writeHeaderTracker to properly verify deferred flushing

Co-authored-by: fzipi <3012076+fzipi@users.noreply.github.com>

* fix(lint): check error return values for ProcessRequestBody and Write

Co-authored-by: fzipi <3012076+fzipi@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: fzipi <3012076+fzipi@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants