Improve HTTP error handling.
Improve HTTP error handling.

Contain the following upstream commits:
- 6e5c0a79044d3d80a22d94049eeb509ea040efac
  - Reverted because it does not apply to Decred
- 2b780d16b042054d07aa322146194118fd7f7b81

jrick/btcd,decred/dcrd,jrick/dcrd,decred/dcrd,jrick/btcd,jrick/dcrd,jrick/btcd