The jruby workaround for handling trailing newlines didn't work for me. I kept getting timeouts. (The timeouts also seem to have issues under jruby but that doesn't matter for this pull request.) Looking at the code, using read_socket.ready? to drain trailing newlines looked race-prone and wacky even when it "worked" with MRI. I switched things up to treat trailing newlines from one message as preceding newlines on the next message. I've tested with 1.8.7 and jruby in 1.8 and 1.9 modes.
Another commit handles eof while reading the headers.
The third uses << instead of += when concatenating strings from the server. No need to create a new object every time, and avoid O(n^2) when no content-length is given.
The jruby workaround for handling trailing newlines didn't work for me. I kept getting timeouts. (The timeouts also seem to have issues under jruby but that doesn't matter for this pull request.) Looking at the code, using read_socket.ready? to drain trailing newlines looked race-prone and wacky even when it "worked" with MRI. I switched things up to treat trailing newlines from one message as preceding newlines on the next message. I've tested with 1.8.7 and jruby in 1.8 and 1.9 modes.
Another commit handles eof while reading the headers.
The third uses << instead of += when concatenating strings from the server. No need to create a new object every time, and avoid O(n^2) when no content-length is given.