httppeer: use util.readexactly() to abort on incomplete responses

Authored by av6.

Description

httppeer: use util.readexactly() to abort on incomplete responses

Plain resp.read(n) may not return exactly n bytes when we need, and to detect
such cases before trying to interpret whatever has been read, we can use
util.readexactly(), which raises an Abort when stream ends unexpectedly. In the
first case here, readexactly() prevents a traceback with struct.error, in the
second it avoids looking for invalid compression engines.

In this test case, _wraphttpresponse doesn't catch the problem (presumably
because it doesn't know transfer encoding), and the code continues reading the
response until it gets to compression engine data. Maybe there should be checks
before the execution gets there, but I'm not sure where (httplib?)

Details

Committed
av6Sep 8 2018, 9:58 AM
Parents
rHG1fc39367eafd: httppeer: calculate total expected bytes correctly
Branches
Unknown
Tags
Unknown