Fixed some logic errors

- Fixed a case where stream would not be read when a 500 error was received
- Fixed a case where headers might not be read correctly when response is gzipped