Fix POST (and probably other) requests that are retried after 401 Unauthorized

These commits fix a regression and a bug that were preventing POST requests from working when the initial request fails with `401 Unauthorized` and a `WWW-Authenticate` header, and the client retries with a proper `Authorization` header.  Also add tests to catch these problems in the future.