Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Flexible complex routes#31

Merged
albertodebortoli merged 11 commits into
justeat:masterfrom
antoniostrijdom:flexible-complex-routes
May 18, 2021
Merged

Flexible complex routes#31
albertodebortoli merged 11 commits into
justeat:masterfrom
antoniostrijdom:flexible-complex-routes

Conversation

@antoniostrijdom

Copy link
Copy Markdown
Contributor

Shock now uses the entire route request (method, path, params, etc) for the key in the internal routing dictionary. This makes complex routes much more flexible, allowing registration of multiple routes with the same urlPath.

This PR:

  • Adds Equatable and Hashable support to the MockHTTPRoute enum (and adds copious tests).
  • Uses the MockHTTPRoute as the key in the PathHandlerMapping (now RouteHandlerMapping).
  • Moves the notFoundHandler to the MiddlewareContext.


let context = _MiddlewareContext(requestContext: requestContext,
responseContext: responseContext) {
responseContext: responseContext,

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.

This could be formatted better.

@Henbyr Henbyr left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

public protocol MiddlewareContext {
var requestContext: MiddlewareRequestContext { get }
var responseContext: MiddlewareResponseContext { get }
var notFoundHandler: HandlerClosure? { get }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure I like this as it circumvents the standard middleware pattern and is letting NIO implementation details bleed into the context interface - the middleware shouldn't need to know about special HTTP handling cases; the purpose of middleware is to be generic enough so as to allow the implementor to cover these cases themself.

No need to hold up the PR for this, but I'll have a think about how the same functionality can be achieved without the interface bleed.

@albertodebortoli albertodebortoli merged commit 127c882 into justeat:master May 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants