Skip to content

Add middleware example#17

Open
FranzBusch wants to merge 1 commit intomainfrom
fb-middleware-example
Open

Add middleware example#17
FranzBusch wants to merge 1 commit intomainfrom
fb-middleware-example

Conversation

@FranzBusch
Copy link
Member

@FranzBusch FranzBusch commented Nov 28, 2025

This PR adds an example showcasing how middleware can be used to intercept requests handled by a server and performed by a client. In detail, this PR adds a logging and request handling middleware. The logging middleware is capable of inspecting every single part of the request including the individual chunks read.

Copy link
Contributor

@czechboy0 czechboy0 left a comment

Choose a reason for hiding this comment

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

This is awesome - the logging middleware is a great example of a fully powerful middleware that also inspects individual body chunks. Though it does make it appear pretty complicated - I wonder if you could add (in a subsequent PR) a simpler middleware example that doesn't need to implement its own reader/writer, and only inspects the headers/trailers, so in theory should be much simpler.

RequestReader.FinalElement == HTTPFields?,
ResponseWriter: ConcludingAsyncWriter & ~Copyable,
ResponseWriter.Underlying.WriteElement == UInt8,
ResponseWriter.FinalElement == HTTPFields?
Copy link
Contributor

Choose a reason for hiding this comment

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

These 6 constraints repeat in many places, should we provide two protocols, one for each tuple of 3, to make it more readable?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm not sure if we want to introduce a separate protocol for this honestly. Not even sure if that would work since that protocol needs to inherit from the other protocol.

This PR adds an example showcasing how middleware can be used to intercept requests handled by a server. In detail, this PR adds a logging and request handling middleware. The logging middleware is capable of inspecting every single part of the request including the individual chunks read.
@FranzBusch FranzBusch force-pushed the fb-middleware-example branch from 5ffce3f to 0761920 Compare December 1, 2025 14:46
@FranzBusch FranzBusch changed the title Add middleware server example Add middleware example Dec 1, 2025
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