1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.internal.impl.transport.http;
20
21 import javax.inject.Named;
22 import javax.inject.Singleton;
23
24 import java.util.Arrays;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.function.Function;
29
30 import org.eclipse.aether.internal.impl.checksum.Md5ChecksumAlgorithmFactory;
31 import org.eclipse.aether.internal.impl.checksum.Sha1ChecksumAlgorithmFactory;
32 import org.eclipse.aether.spi.connector.transport.http.ChecksumExtractorStrategy;
33
34
35
36
37 @Singleton
38 @Named(XChecksumExtractor.NAME)
39 public final class XChecksumExtractor extends ChecksumExtractorStrategy {
40 public static final String NAME = "xChecksum";
41
42
43
44
45
46 private static final List<String> HEADER_PREFIXES = Arrays.asList(
47
48 "x-checksum-",
49
50 "x-goog-meta-checksum-",
51
52 "x-amz-meta-checksum-");
53
54 @Override
55 public Map<String, String> extractChecksums(Function<String, String> headerGetter) {
56 for (String headerPrefix : HEADER_PREFIXES) {
57 Map<String, String> result = extractChecksums(headerGetter, headerPrefix);
58 if (!result.isEmpty()) {
59 return result;
60 }
61 }
62 return null;
63 }
64
65 private static Map<String, String> extractChecksums(Function<String, String> headerGetter, String headerPrefix) {
66 HashMap<String, String> result = new HashMap<>();
67 String value = headerGetter.apply(headerPrefix + "sha1");
68 if (value != null) {
69 result.put(Sha1ChecksumAlgorithmFactory.NAME, value);
70 }
71 value = headerGetter.apply(headerPrefix + "md5");
72 if (value != null) {
73 result.put(Md5ChecksumAlgorithmFactory.NAME, value);
74 }
75 return result;
76 }
77 }