Skip to content

Conversation

@fkesheh
Copy link

@fkesheh fkesheh commented Nov 29, 2025

When a ResponseProtocolError occurs (e.g., upstream connection failure), addons can now set flow.response in the error hook to serve a custom response instead of the default 502 error.

This enables common use cases like:

  • Serving cached responses when upstream is unavailable
  • Implementing circuit breaker patterns with fallback responses
  • Providing custom error pages instead of generic 502 errors
  • Graceful degradation during network failures

Implementation details:

  • Tracks whether response was set before or during the error hook
  • Only applies override when response is newly set in the hook
  • Sets proper timestamps on the override response
  • Uses raw_content for consistency with send_response()
  • Handles trailers correctly
  • Works across HTTP/1.1, HTTP/2, and HTTP/3

Tests added for all three HTTP versions covering both the override case and the default behavior case.

Description

Checklist

  • I have updated tests where applicable.
  • I have added an entry to the CHANGELOG.

When a ResponseProtocolError occurs (e.g., upstream connection failure),
addons can now set flow.response in the error hook to serve a custom
response instead of the default 502 error.

This enables common use cases like:
- Serving cached responses when upstream is unavailable
- Implementing circuit breaker patterns with fallback responses
- Providing custom error pages instead of generic 502 errors
- Graceful degradation during network failures

Implementation details:
- Tracks whether response was set before or during the error hook
- Only applies override when response is newly set in the hook
- Sets proper timestamps on the override response
- Uses raw_content for consistency with send_response()
- Handles trailers correctly
- Works across HTTP/1.1, HTTP/2, and HTTP/3

Tests added for all three HTTP versions covering both the override
case and the default behavior case.
@fkesheh fkesheh force-pushed the feature/error-hook-response-override branch from fc35690 to bf24944 Compare November 29, 2025 13:40
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.

1 participant