squeaky-pl / japronto

Screaming-fast Python 3.5+ HTTP toolkit integrated with pipelining HTTP server based on uvloop and picohttpparser.
MIT License
8.61k stars 581 forks source link

Switchable CProtocol #64

Closed danields761 closed 5 years ago

danields761 commented 7 years ago

Hi everyone.

I'am developing REST service which serves both common http and ws requests, which handlers is in same resource path (for example GET '/api/resource', WS '/api/resource/subscribe'). I have created simple japronto server which accept all ws connections, upgrade them and log into console all raw incoming data.

As you can see async handler receives connection, then create WS protocol, perform protocol hot switch (call transport.set_protocol) and that is got.

The problem is that variety WS implementation already written for asyncio (websockets for example). It is impossible to use them directly, without significant changes, because headers and even request body already read from attached transport by CProtocol.

My propose is to rewrite CProtocol or add new one which handle connection, wait for request method and path, then switch to appropriate protocol, which is specified by developer (maybe associated with path).

I think this feature will be very helpful, but i can't figure out how to do that more correctly. Can you suggest me or point in the right direction?)

danields761 commented 5 years ago

Not actual right now