HTTPServerAuthenticationMiddleware example#161
Conversation
| // TODO: what should it mean when a middleware throws? | ||
| throw AuthenticationError() |
There was a problem hiding this comment.
It seems reasonable to me that a throwing middleware indicates that a request wasn't handled e.g blocked before it reached the final handler.
There was a problem hiding this comment.
Right now swift-http-server will re-throw https://github.com/swift-server/swift-http-server/blob/446a2783ccadacec8c8ef2051926c8dbe231ef33/Sources/NIOHTTPServer/NIOHTTPServer.swift#L292. This will result in the connection being closed for h1: https://github.com/swift-server/swift-http-server/blob/446a2783ccadacec8c8ef2051926c8dbe231ef33/Sources/NIOHTTPServer/NIOHTTPServer%2BHTTP1_1.swift#L48.
You could have an ErrorSwallowingMiddleware that drops any throws from subsequent middlewares or the terminal handler, but then the terminal handler doesn't have a way of eliciting a throw that's propagated to the server.
Either way, it's probably worth at least specifying expected server behavior when the request handler throws.
Motivation
Demonstrate auth middleware and how it must throw.
Modifications
Add HTTPServerAuthenticationMiddleware example.
Result
New example.
Test Plan
N/A