Skip to content

Conversation

svozza
Copy link
Contributor

@svozza svozza commented Sep 8, 2025

Summary

This commit introduces a mechanism for middleware to manipulate HTTP responses sent by the handler. This is required for middleware such as CORS.

Changes

BaseRouter.ts

  • HandlerOptions now exposes a res field. This is a Web API Response object that represents the response that will be sent. This allows middleware that runs after the handler has been executed to manipulate the response before it is finally sent
  • The middleware that runs the handler now does not return the result but mutates the res field and adds the response there
  • Renamed RequestOptions to RequestContext because it now deals with responses as well as requests

Converters.ts

  • Created new function to convert HandlerResponse for a Web API Response object.

Tests:

  • Added middleware header precedence testing ('last write wins' behavior)
  • Added tests for new handlerResultToResponse fucntion
  • Implemented direct unit tests for composeMiddleware

Issue number: closes #4393


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@boring-cyborg boring-cyborg bot added event-handler This item relates to the Event Handler Utility tests PRs that add or change tests labels Sep 8, 2025
@pull-request-size pull-request-size bot added the size/XL PRs between 500-999 LOC, often PRs that grown with feedback label Sep 8, 2025
@svozza svozza self-assigned this Sep 8, 2025
@svozza svozza requested a review from dreamorosi September 8, 2025 11:58
@svozza svozza force-pushed the event-handler/response-manipulation branch 3 times, most recently from 8acbf50 to d0a9c8f Compare September 8, 2025 12:30
@svozza svozza force-pushed the event-handler/response-manipulation branch 2 times, most recently from 9fdcd19 to 34619b3 Compare September 8, 2025 12:49
@svozza svozza force-pushed the event-handler/response-manipulation branch from 34619b3 to 3761ba0 Compare September 8, 2025 14:14
dreamorosi
dreamorosi previously approved these changes Sep 8, 2025
Copy link

sonarqubecloud bot commented Sep 8, 2025

@svozza svozza merged commit 35a510d into main Sep 9, 2025
38 checks passed
@svozza svozza deleted the event-handler/response-manipulation branch September 9, 2025 07:07
@svozza svozza added this to the Event Handler Beta (priority) milestone Sep 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

event-handler This item relates to the Event Handler Utility size/XL PRs between 500-999 LOC, often PRs that grown with feedback tests PRs that add or change tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Implement Middleware for REST Event Handler

2 participants