| 1014 | |
| 1015 | |
| 1016 | Future<Nothing> DockerFetcherPluginProcess::_fetchBlob( |
| 1017 | const URI& uri, |
| 1018 | const string& directory, |
| 1019 | const URI& blobUri, |
| 1020 | const http::Headers& basicAuthHeaders) |
| 1021 | { |
| 1022 | // TODO(jieyu): This extra 'curl' call can be avoided if we can get |
| 1023 | // HTTP headers from 'download'. Currently, 'download' only returns |
| 1024 | // the HTTP response code because we don't support parsing HTTP |
| 1025 | // headers alone. Revisit this once that's supported. |
| 1026 | return curl(blobUri, basicAuthHeaders, stallTimeout) |
| 1027 | .then(defer(self(), [=](const http::Response& response) -> Future<Nothing> { |
| 1028 | // We expect a '401 Unauthorized' response here since the |
| 1029 | // 'download' with the same URI returns a '401 Unauthorized'. |
| 1030 | if (response.code != http::Status::UNAUTHORIZED) { |
| 1031 | return Failure( |
| 1032 | "Expecting a '401 Unauthorized' response when fetching a blob, " |
| 1033 | "but get '" + response.status + "' instead"); |
| 1034 | } |
| 1035 | |
| 1036 | return getAuthHeader(uri.path(), blobUri, basicAuthHeaders, response) |
| 1037 | .then(defer(self(), [=]( |
| 1038 | const http::Headers& authHeaders) -> Future<Nothing> { |
| 1039 | return download( |
| 1040 | blobUri, |
| 1041 | strings::trim(stringify(blobUri)), |
| 1042 | directory, |
| 1043 | authHeaders, |
| 1044 | stallTimeout) |
| 1045 | .then(defer(self(), [=](int code) -> Future<Nothing> { |
| 1046 | if (code == http::Status::OK) { |
| 1047 | return Nothing(); |
| 1048 | } |
| 1049 | |
| 1050 | #ifdef __WINDOWS__ |
| 1051 | return urlFetchBlob(uri, directory, blobUri, authHeaders); |
| 1052 | #else |
| 1053 | return Failure( |
| 1054 | "Unexpected HTTP response '" + http::Status::string(code) + |
| 1055 | "' when trying to download blob '" + |
| 1056 | strings::trim(stringify(blobUri)) + |
| 1057 | "' with schema 1 manifest"); |
| 1058 | #endif |
| 1059 | })); |
| 1060 | })); |
| 1061 | })); |
| 1062 | } |
| 1063 | |
| 1064 | |
| 1065 | #ifdef __WINDOWS__ |