Skip to content

docs: clarify async onResponse usage#478

Open
barry166 wants to merge 1 commit into
fastify:mainfrom
barry166:docs/async-on-response
Open

docs: clarify async onResponse usage#478
barry166 wants to merge 1 commit into
fastify:mainfrom
barry166:docs/async-on-response

Conversation

@barry166

Copy link
Copy Markdown

Summary

  • Documents async onResponse usage for reading an upstream response before replying.
  • Updates the TypeScript hook type to allow Promise<void>.
  • Adds runtime and tstyche coverage for async onResponse callbacks.

Fixes #380.

Verification

  • npm run test:unit -- test/onResponse.test.js
  • npm run test:typescript
  • npm run lint
  • git diff --check

I also ran npm test; the touched onResponse and TypeScript tests passed, but the full local suite has unrelated failures in this checkout:

  • invalid-target tests return 500 instead of the expected 503
  • Unix socket tests fail with listen EINVAL on long local socket paths under this workspace

Contribution notes

The runtime already allows an async onResponse callback to wait before sending a replacement body, but the docs and TypeScript hook type only described synchronous callbacks. This records the supported usage with runtime and type coverage instead of changing the proxy path.

Constraint: fastify#380 asks about async onResponse usage and maintainers requested PRs with tests
Rejected: Change runtime control flow | async callbacks that call reply.send after await already work in the existing callback path
Confidence: high
Scope-risk: narrow
Directive: Keep async callback errors user-handled unless the runtime explicitly adds async error routing
Tested: npm run test:unit -- test/onResponse.test.js; npm run test:typescript; npm run lint; git diff --check
Not-tested: Full npm test has pre-existing local failures for invalid-target expectations and Unix socket path length on this macOS checkout
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.

Async onResponse

1 participant