http: Handle hex/base64 encodings properly

This is a backport of 6d3d60aced39d59eaa5e705b7d822c227d0d3dae for
v0.10.