This was copied verbatim from `http_api`. I'd rather leave it as-is for now to minimise the possibility of breaking things.