jgarzik / python-bitcoinrpc

Python interface to bitcoin's JSON-RPC API
GNU Lesser General Public License v2.1
644 stars 304 forks source link

tests: Check Content-Type header returned from RPC server #65

Closed maflcko closed 8 years ago

maflcko commented 8 years ago

Work by @laanwj; Cherry-picked from https://github.com/bitcoin/bitcoin/pull/7833:


Check the Content-Type header that is returned from the RPC server. Only if it is application/json the data is supposed to be parsed as JSON.

This gives better reporting if the HTTP server happens to return an error that is not JSON-formatted, which is the case if it happens at a lower level before JSON-RPC kicks in.

Before: Unexpected exception caught during testing: No JSON object could be decoded

After: JSONRPC error: non-JSON HTTP response with '403 Forbidden' from server

jgarzik commented 8 years ago

Merged - however this is not ideal. It is more flexible to conditionalize this behavior on whether or not parsing the body as Json succeeds or fails, which one must do anyway.

laanwj commented 8 years ago

This solves a different issue: it shouldn't even try to parse as JSON if the content type is not application/json (for example, an HTML error message) When the content is marked as JSON and fails to parse that's indeed a different error, and not handled here.