-
Notifications
You must be signed in to change notification settings - Fork 542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added scopes, make headers and status code public #410
Conversation
Generated by 🚫 Danger |
Hey, @apocolipse Thanks for taking the time to create this PR 👍. The PR in general looks good just I just have a few comments about it:
server.middleware.append { request in
print("Middleware: \(request.address ?? "unknown address") -> \(request.method) -> \(request.path)")
return nil
} In the above example, it's used to print all the request that comes through the server but it can be used for the same purpose you used above.
|
@Vkt0r When I looked at the middleware in the library i wasn't able to figure out an easy way to "wrap" the whole request handler (in order to get time taken to print), is there an easy way for that? In any case the TryingRequestHandler example is something that probably should be added to the library (though I'm averse to default behavior that users can't change, so maybe just an example in the README? idk) RE: RE: Access levels, yeah its annoying but everything needs to be evaluated in a library for who's going to use it, basic stuff like headers, statusCode, body, etc. should be openly available |
The current Middleware can be used exactly like you're using it right now for the case of measuring the time of the response but you need to be careful as it would be used for all the requests in case a response is given I'm afraid.
Yes, maybe it could be added in a way to handle errors for certain functions I can think in #407 🤔. But I think your point of docs is very good, we could add some example of this uses of Middlewares to the docs. I've been working in docs for the library so I will mention some of your examples there 👍.
Yes, that's true it would be more readable and easy to use if it would be a read-only computed property. It's true that the syntax Can you please update the entry in the |
@Vkt0r Updated CHANGELOG.md, also updated |
@apocolipse Thanks for your changes, this looks very good! Just a minor comment, I'm seeing a lot of extra spaces and extra lines added in several files, can you please take care of these? |
Added scopes, make headers and status code public
manifest
,ontouchstart
anddataText
vars to Scopesheaders()
andstatusCode
public,statusCode
a computed variable.These are just a few minor changes that I've made for a project I'm using Swifter for.
Making the response properties public is necessary to create custom middle-middle-wares (proper terminology? /shrug) like the ones I'm using below:
These can be combined/chained to wrap around request handlers, and are extremely easy to add to normal request handling closures by dropping the name right in front, examples: