Creates an HttpRequest and sets several parameters that are common to all requests. All code (in GcsFileSystem) that creates an HttpRequest should go through this method, rather than directly using http_request_factory_.
| 1756 | // requests. All code (in GcsFileSystem) that creates an HttpRequest should |
| 1757 | // go through this method, rather than directly using http_request_factory_. |
| 1758 | Status GcsFileSystem::CreateHttpRequest(std::unique_ptr<HttpRequest>* request) { |
| 1759 | std::unique_ptr<HttpRequest> new_request{http_request_factory_->Create()}; |
| 1760 | if (dns_cache_) { |
| 1761 | dns_cache_->AnnotateRequest(new_request.get()); |
| 1762 | } |
| 1763 | |
| 1764 | string auth_token; |
| 1765 | { |
| 1766 | tf_shared_lock l(mu_); |
| 1767 | TF_RETURN_IF_ERROR( |
| 1768 | AuthProvider::GetToken(auth_provider_.get(), &auth_token)); |
| 1769 | } |
| 1770 | |
| 1771 | new_request->AddAuthBearerHeader(auth_token); |
| 1772 | |
| 1773 | if (additional_header_) { |
| 1774 | new_request->AddHeader(additional_header_->first, |
| 1775 | additional_header_->second); |
| 1776 | } |
| 1777 | |
| 1778 | if (stats_ != nullptr) { |
| 1779 | new_request->SetRequestStats(stats_->HttpStats()); |
| 1780 | } |
| 1781 | |
| 1782 | if (!throttle_.AdmitRequest()) { |
| 1783 | return errors::Unavailable("Request throttled"); |
| 1784 | } |
| 1785 | |
| 1786 | *request = std::move(new_request); |
| 1787 | return Status::OK(); |
| 1788 | } |
| 1789 | |
| 1790 | } // namespace tensorflow |
| 1791 |