Skip to content

fix: correct HTTP middleware logging and recovery - #93

Open
raeperd wants to merge 4 commits into
mainfrom
codex/request-outcomes
Open

fix: correct HTTP middleware logging and recovery#93
raeperd wants to merge 4 commits into
mainfrom
codex/request-outcomes

Conversation

@raeperd

@raeperd raeperd commented Sep 6, 2026

Copy link
Copy Markdown
Owner

Summary

A panic previously skipped access logging, while recorder errors could make logs disagree with the response sent to the client. Keep accesslog and recovery as separate middleware, placing accesslog outside recovery so its deferred log observes the recovered response. Each middleware uses its own recorder.

Recovery sends a generic 500 before a final response is committed, preserves ErrAbortHandler, and aborts partial responses after a panic. The access log distinguishes completed and aborted requests. Correct recorder behavior retains the first accepted final status, handles informational headers under HTTP/1 and HTTP/2, records effective implicit 200 responses, and counts bytes actually accepted by the writer.

Writer support stays small: ResponseController flushing and pprof's write-deadline extension. Connection hijacking, direct Flusher support, and generic Unwrap forwarding are outside this template's contract. No dependencies or lifecycle changes.

Testing

  • Tests compose accesslog(recovery(handler)) and assert client responses alongside logs over real HTTP connections, including panic/abort behavior, informational headers, duplicate final headers, empty responses, flushing, and health/debug routes.
  • Focused writer tests cover short writes, partial failures, and unsupported/failed flushes.
  • make build test passed (race/shuffle enabled; 84.0% statement coverage).
  • golangci-lint run --allow-serial-runners passed.
  • go run golang.org/x/tools/cmd/deadcode@latest -test ./... passed.

@raeperd

raeperd commented Sep 6, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@coveralls

coveralls commented Sep 6, 2026

Copy link
Copy Markdown

Coverage Status

coverage: 83.133% (+3.0%) from 80.128% — codex/request-outcomes into main

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 6, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-06T06:33:34.384062Z 3d4df1a Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3d4df1ab39

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread main.go Outdated
@raeperd
raeperd marked this pull request as ready for review September 6, 2026 06:38
@raeperd
raeperd marked this pull request as draft September 6, 2026 06:51
@raeperd
raeperd marked this pull request as ready for review September 6, 2026 06:54
@raeperd
raeperd marked this pull request as draft September 6, 2026 07:23
@raeperd raeperd changed the title fix: give HTTP request outcomes one owner fix: correct HTTP middleware logging and recovery Sep 6, 2026
@raeperd
raeperd marked this pull request as ready for review September 6, 2026 07:27
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