You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2022/01/30 15:53:35 UTC

[GitHub] [maven-resolver] michael-o commented on a change in pull request #140: [MRESOLVER-231] Extend smart checksum support

michael-o commented on a change in pull request #140:
URL: https://github.com/apache/maven-resolver/pull/140#discussion_r795205406



##########
File path: maven-resolver-transport-http/src/main/java/org/eclipse/aether/transport/http/HttpTransporterFactory.java
##########
@@ -37,17 +42,39 @@
 public final class HttpTransporterFactory
     implements TransporterFactory
 {
+    private static final Map<String, ChecksumExtractor> EXTRACTORS;
+
+    static
+    {
+        HashMap<String, ChecksumExtractor> map = new HashMap<>();
+        map.put( NexusChecksumExtractor.NAME, new NexusChecksumExtractor() );

Review comment:
       Does this apply for Nexus 2 an 3?

##########
File path: maven-resolver-transport-http/src/main/java/org/eclipse/aether/transport/http/XChecksumChecksumExtractor.java
##########
@@ -0,0 +1,86 @@
+package org.eclipse.aether.transport.http;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.http.Header;
+import org.apache.http.HttpResponse;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.util.Collections;
+import java.util.Map;
+
+/**
+ * A component extracting {@code x-} non-standard style checksums from response headers.
+ * Tried headers (in order):
+ * <ul>
+ *     <li>{@code x-checksum-sha1} - Maven Central and other CDNs</li>
+ *     <li>{@code x-checksum-md5} - Maven Central and other CDNs</li>
+ *     <li>{@code x-goog-meta-checksum-sha1} - GCS</li>
+ *     <li>{@code x-goog-meta-checksum-md5} - GCS</li>
+ * </ul>
+ *
+ * @since TBD
+ */
+@Singleton
+@Named( XChecksumChecksumExtractor.NAME )
+public class XChecksumChecksumExtractor
+        extends ChecksumExtractor
+{
+    public static final String NAME = "x-checksum";
+
+    @Override
+    public Map<String, String> extractChecksums( HttpResponse response )
+    {
+        String value;
+        // Central style: x-checksum-sha1: c74edb60ca2a0b57ef88d9a7da28f591e3d4ce7b
+        value = extractChecksum( response, "x-checksum-sha1" );
+        if ( value != null )
+        {
+            return Collections.singletonMap( "SHA-1", value );
+        }
+        // Central style: x-checksum-md5: 9ad0d8e3482767c122e85f83567b8ce6
+        value = extractChecksum( response, "x-checksum-md5" );
+        if ( value != null )
+        {
+            return Collections.singletonMap( "MD5", value );
+        }
+        // Google style: x-goog-meta-checksum-sha1: c74edb60ca2a0b57ef88d9a7da28f591e3d4ce7b
+        value = extractChecksum( response, "x-goog-meta-checksum-sha1" );
+        if ( value != null )
+        {
+            return Collections.singletonMap( "SHA-1", value );
+        }
+        // Central style: x-goog-meta-checksum-sha1: 9ad0d8e3482767c122e85f83567b8ce6
+        value = extractChecksum( response, "x-goog-meta-checksum-md5" );
+        if ( value != null )
+        {
+            return Collections.singletonMap( "MD5", value );
+        }
+
+        return null;
+    }

Review comment:
       I am confused, can't multiple headers appear on the response? Why return on the first found?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org