jlusiardi / homekit_python

A python implementation to work as both HomeKit controller and accessory.
Apache License 2.0
221 stars 41 forks source link

Tweak HttpResponse class for use with async clients #162

Closed Jc2k closed 5 years ago

Jc2k commented 5 years ago

In my asyncio branch i end up copying the whole of HttpResponse class. I did this so the PR didn't contain lots of changes to the sync code. But this is actually a fairly small change we can review in isolation, so if we review it now it will make the aioclient branch 133 lines of code smaller and easier to review!

The aio client uses asyncio.Protocol and this means the network stack calls us when data is received, rather than us pulling (and blocking on) data from the network stack. This means we don't control how much data we get handed - it could be 2 complete EVENT/1.0 responses. This PR just tweaks the parser so we can get back the data that wasn't consumed by the parser, allowing it to be fed into the next instance of HTTPResponse.

It doesn't change the ABI for the existing code - the existing code can just ignore the return value of parse.

jlusiardi commented 5 years ago

lgtm