Fix a potential race condition with agent credentials.
Fix a potential race condition with agent credentials.

When the agent sends a request to the proxy server, it includes an
OAuth access token in the 'Authorization' header to identify itself.

Previously, that token was being generated as soon as the agent had
a request to forward to the backend server. However, that token was
only guaranteed to be valid for 10 seconds, and the backend server
could take longer than that to respond.

This allowed a scenario where the OAuth access token would expire
between the time the request to the proxy was generated and the
time when it was actually sent to the proxy server.

This commit fixes that issue by delaying the proxy request round
trip until we know that the request has enough data to be sent
to the proxy server. This amounts to the response from the backend
server either having some of its body written (for a non-empty
backend response), or the response being finished (for an empty
backend response).

google/inverting-proxy