Fixed a EOFException when reading headers at the edge of the file

This time I'm adding the test first expecting Travis to complain. I'll submit the fix after that.