| 832 | |
| 833 | |
| 834 | Future<Nothing> DockerFetcherPluginProcess::__fetch( |
| 835 | const URI& uri, |
| 836 | const string& directory, |
| 837 | const http::Headers& authHeaders, |
| 838 | const http::Response& response) |
| 839 | { |
| 840 | if (response.code != http::Status::OK) { |
| 841 | return Failure( |
| 842 | "Unexpected HTTP response '" + response.status + "' " |
| 843 | "when trying to get the manifest"); |
| 844 | } |
| 845 | |
| 846 | CHECK_EQ(response.type, http::Response::BODY); |
| 847 | |
| 848 | Option<string> contentType = response.headers.get("Content-Type"); |
| 849 | if (contentType.isNone()) { |
| 850 | return Failure("No Content-Type present"); |
| 851 | } |
| 852 | |
| 853 | // NOTE: Docker supports the following five media types. |
| 854 | // |
| 855 | // V2 schema 1 manifest: |
| 856 | // 1. application/vnd.docker.distribution.manifest.v1+json |
| 857 | // 2. application/vnd.docker.distribution.manifest.v1+prettyjws |
| 858 | // 3. application/json |
| 859 | // |
| 860 | // For more details, see: |
| 861 | // https://docs.docker.com/registry/spec/manifest-v2-1/ |
| 862 | // |
| 863 | // V2 schema 2 manifest: |
| 864 | // 1. application/vnd.docker.distribution.manifest.v2+json |
| 865 | // 2. application/vnd.docker.distribution.manifest.list.v2+json |
| 866 | // (manifest list is not supported yet) |
| 867 | // |
| 868 | // For more details, see: |
| 869 | // https://docs.docker.com/registry/spec/manifest-v2-2/ |
| 870 | bool isV2Schema1 = |
| 871 | strings::startsWith( |
| 872 | contentType.get(), |
| 873 | "application/vnd.docker.distribution.manifest.v1") || |
| 874 | strings::startsWith( |
| 875 | contentType.get(), |
| 876 | "application/json"); |
| 877 | |
| 878 | // TODO(gilbert): Support manifest list (fat manifest) in V2 Schema2. |
| 879 | bool isV2Schema2 = |
| 880 | contentType.get() == "application/vnd.docker.distribution.manifest.v2+json"; |
| 881 | |
| 882 | if (isV2Schema1) { |
| 883 | // Parse V2 schema 1 image manifest. |
| 884 | Try<spec::v2::ImageManifest> manifest = spec::v2::parse(response.body); |
| 885 | if (manifest.isError()) { |
| 886 | return Failure( |
| 887 | "Failed to parse the V2 Schema 1 image manifest: " + |
| 888 | manifest.error()); |
| 889 | } |
| 890 | |
| 891 | // Save manifest to 'directory'. |
nothing calls this directly
no test coverage detected