smartrpyc.server.middleware
Note
The middleware handling part needs some rethinking.
- How do we decide whether to interrupt the request upon
exception raising inside middleware?
- Do we want to execute the post middleware in any case, or just
in case the request was processed in a clean way?
- I think POST middleware should have a chance to know that an
exception was raised and do something about it.
- When should we use middleware and when would it be better to
subclass Server instead?
Middleware base
Middleware can be used to extend the server functionality, by adding
methods to be executed before and after the request is processed.
-
class smartrpyc.server.middleware.ServerMiddlewareBase[source]
Base class for the server middleware.
This is mostly a reminder for methods signatures, but subclassing
from this object is not mandatory for middleware classes, as long
as they expose a pre() and/or post() methods.
-
post(request, method, response, exception)[source]
This method will be executed after the request is processed
and a response returned by the called method.
Parameters: |
- request – a smartrpyc.server.Request object
- method – the method that has been called to process the request
and generate the response
- response – the response object returned from the method call (if any)
- exception – the exception raised by the method call (if any)
|
-
pre(request, method)[source]
This method will be executed before the request is processed.
Parameters: |
- request – a smartrpyc.server.Request object
- method – the method that is going to be called to process the request
and generate the response
|
This method has different ways to hijack the request/response
process:
- Raise a DirectResponse exception,
containing some object to be directly returned to the client
- Raise a SetMethod exception,
containing an alternate method to be called
- Raise a generic exception that will terminate the request
processing and will be returned to the client directly.
Introspection Middleware
-
class smartrpyc.server.middleware.IntrospectionMiddleware[source]
Middleware adding the .dir() and .doc() methods to be used
for introspecting the exposed methods.
-
pre(request, method)[source]