Skip to content

HTTPServerAuthenticationMiddleware example#161

Open
ehaydenr wants to merge 1 commit into
apple:mainfrom
ehaydenr:auth
Open

HTTPServerAuthenticationMiddleware example#161
ehaydenr wants to merge 1 commit into
apple:mainfrom
ehaydenr:auth

Conversation

@ehaydenr
Copy link
Copy Markdown
Contributor

Motivation

Demonstrate auth middleware and how it must throw.

Modifications

Add HTTPServerAuthenticationMiddleware example.

Result

New example.

Test Plan

N/A

Comment on lines +93 to +94
// TODO: what should it mean when a middleware throws?
throw AuthenticationError()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

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