endpoints
endpoints copied to clipboard
InterfaceRequest
Currently, we basically make all the interfaces look a bit like a WSGI request, then http.Request
can use .environ
and stuff to find information like IP address and host.
I think it would be better to have an InterfaceRequest
wrapper that would take the raw request and then the interface could implement the supported methods, and then http.Request
would be instantiated like this:
request = Request(InterfaceRequest(raw_request))
I think the class would be something like:
class InterfaceRequest(object):
def __init__(self, raw_request):
self.raw = raw_request
def get_headers(self):
raise NotImplementedError()
...
This was my original note:
create an interface request class that can handle bridging between the interface (uwsgi, asgi) and the request object. So basically, the interface would create an InterfaceRequest class and pass that to Request, then Request would use InterfaceRequest for things like .ip and .scheme
So the big question is, why would we do this over just having these things set directly on http.request
in the interface's create_request
method like we kind of do now? This solution would make it so the code is run on demand instead of all ran in the create_request
method. Likewise, it would provide a standard template for what needs to be implemented, right now to add a new interface I usually look at what a previous interface's create_request
method is doing.
Biggest annoyance would be all the tests that just create a request object, I'd need to change all those to take the InterfaceRequest
instance, and there are a lot of tests.