I'm using Python's BaseHTTPRequestHandler class to build a web server.  I want to add an endpoint for WebSockets.  This means that I need to read whatever is available from the handler's rfile, so that I can process messages one by one, as I'm receiving them (instead of having to read the while input).
I tried using different combinations of 'read' (eg. with a big buffer, thinking that it'd return early with less data if less data was available; with no parameter, but then it just means to read until EOF) but couldn't get this to work.
I can think of two solutions:

To call read(1): to read bytes one by one. I'd rather not do this, as I'm not sure what the buffering semantics are (eg. I wouldn't want a syscall per byte read).
To temporally make the file non-blocking, then attempt a read for a chunk of data, then make it blocking, then attempt a read for 1 byte.  This seems rather messy.  Another option I can think of is to just use non-blocking sockets, but this wouldn't seem to work so well with my current threaded framework.

Any ideas of how to get read to return whatever data is available?
WebSockets aren't HTTP, so you can't really handle them with an HTTP request handler.
However, using BaseHTTPRequestHandler with HTTP, you would normally be reading only the exact amount of data you expect (for instance, as specified in the Content-length header.)
Python, BaseHTTPRequestHandler: how to read what's available on file from socket?