| 977 | |
| 978 | |
| 979 | Future<Nothing> DockerFetcherPluginProcess::fetchBlob( |
| 980 | const URI& uri, |
| 981 | const string& directory, |
| 982 | const http::Headers& authHeaders) |
| 983 | { |
| 984 | URI blobUri = getBlobUri(uri); |
| 985 | |
| 986 | return download( |
| 987 | blobUri, |
| 988 | strings::trim(stringify(blobUri)), |
| 989 | directory, |
| 990 | authHeaders, |
| 991 | stallTimeout) |
| 992 | .then(defer(self(), [=](int code) -> Future<Nothing> { |
| 993 | if (code == http::Status::UNAUTHORIZED) { |
| 994 | // If we get a '401 Unauthorized', we assume that 'authHeaders' |
| 995 | // is either empty or contains the 'Basic' credential, and we |
| 996 | // can use it to request an auth token. |
| 997 | // TODO(chhsiao): What if 'authHeaders' has an expired token? |
| 998 | return _fetchBlob(uri, directory, blobUri, authHeaders); |
| 999 | } |
| 1000 | |
| 1001 | if (code == http::Status::OK) { |
| 1002 | return Nothing(); |
| 1003 | } |
| 1004 | |
| 1005 | #ifdef __WINDOWS__ |
| 1006 | return urlFetchBlob(uri, directory, blobUri, authHeaders); |
| 1007 | #else |
| 1008 | return Failure( |
| 1009 | "Unexpected HTTP response '" + http::Status::string(code) + "' " |
| 1010 | "when trying to download the blob"); |
| 1011 | #endif |
| 1012 | })); |
| 1013 | } |
| 1014 | |
| 1015 | |
| 1016 | Future<Nothing> DockerFetcherPluginProcess::_fetchBlob( |