python-jsonrpc-server icon indicating copy to clipboard operation
python-jsonrpc-server copied to clipboard

Allow any order of headers in base protocol

Open kristopher-h opened this issue 6 years ago • 2 comments

Hi,

Currently python-jsonrpc-server requires the Content-Length header to be sent first. I guess the following snippet is causing the issue:

        content_length = self._content_length(line)

        # Blindly consume all header lines
        while line and line.strip():
             line = self._rfile.readline()

I think it would be good to allow reading headers in any order. The LSP specification doesn't mention anything about order, even though it is listed in one, leaving it a bit open for interpretation.

Let me know if you would like a PR with a suggestion for a fix (assuming you agree with my conclusion that is).

Regards

kristopher-h avatar Sep 18 '18 20:09 kristopher-h

Yup, completely agree. I went for the naive thing just to avoid taking a dependency on some lib with header parsing. Since there’s only one header we really care about though this should still be quite simple

gatesn avatar Sep 18 '18 22:09 gatesn

I did PR to allow for parsing headers in any order here https://github.com/palantir/python-jsonrpc-server/pull/11. I added some additional unit tests to cover some new scenarios as well. If I understood correctly, the intention was that the listen method should never raise. But instead just break on error (corrupt headers/messages)? Feel free to have a look.

kristopher-h avatar Sep 20 '18 20:09 kristopher-h