Add middleware example#17
Conversation
czechboy0
left a comment
There was a problem hiding this comment.
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.
5ffce3f to
0761920
Compare
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.
c0c7c16 to
bb8c3a5
Compare
2ce71b7 to
4a65990
Compare
| next: (consuming NextInput) async throws -> Return | ||
| ) async throws -> Return |
There was a problem hiding this comment.
Would it make sense to allow for separate Return types in next and in intercept? What if a middleware wants to transform next's return value into something else?
There was a problem hiding this comment.
I am not sure that transforming the Return type would work since in the end this is the type that a user returns from their perform closure. Let's keep it to one type for now.
| consuming RequestReader, | ||
| consuming HTTPResponseSender<ResponseWriter> |
There was a problem hiding this comment.
Should these be sending too?
There was a problem hiding this comment.
It would require us to take the sender as sending right now I didn't need that. Let's keep an eye if for some middleware we want this.
| input: consuming Input, | ||
| next: (consuming NextInput) async throws -> Void | ||
| ) async throws | ||
| next: (consuming NextInput) async throws -> Return |
4a65990 to
1a6330e
Compare
6ede67d to
42029f3
Compare
42029f3 to
ffed766
Compare
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.