From cf6d0225e52f7a204199ece08cf6f614c7e32144 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Fri, 19 Jul 2024 17:29:06 +0530 Subject: [PATCH] Look up HTTP headers while ignoring case OpenStack Swift uses lower-case headers. Fixes #664. --- .../CaseInsensitiveImmutableMultimap.java | 51 +++++++++++++++++++ .../java/org/gaul/s3proxy/S3ProxyHandler.java | 5 +- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/gaul/s3proxy/CaseInsensitiveImmutableMultimap.java diff --git a/src/main/java/org/gaul/s3proxy/CaseInsensitiveImmutableMultimap.java b/src/main/java/org/gaul/s3proxy/CaseInsensitiveImmutableMultimap.java new file mode 100644 index 00000000..94b26686 --- /dev/null +++ b/src/main/java/org/gaul/s3proxy/CaseInsensitiveImmutableMultimap.java @@ -0,0 +1,51 @@ +/* + * Copyright 2014-2021 Andrew Gaul + * + * Licensed 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 + * + * https://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. + */ + +package org.gaul.s3proxy; + +import java.util.Collection; +import java.util.Map; + +import com.google.common.collect.ForwardingMultimap; +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.Multimap; + +final class CaseInsensitiveImmutableMultimap + extends ForwardingMultimap { + private final Multimap inner; + + CaseInsensitiveImmutableMultimap(Multimap map) { + var builder = ImmutableMultimap.builder(); + for (Map.Entry entry : map.entries()) { + builder.put(lower(entry.getKey()), entry.getValue()); + } + this.inner = builder.build(); + } + + @Override + protected Multimap delegate() { + return inner; + } + + @Override + public Collection get(String key) { + return inner.get(lower(key)); + } + + private static String lower(String key) { + return key == null ? null : key.toLowerCase(); + } +} diff --git a/src/main/java/org/gaul/s3proxy/S3ProxyHandler.java b/src/main/java/org/gaul/s3proxy/S3ProxyHandler.java index a88e4d54..b0d830d8 100644 --- a/src/main/java/org/gaul/s3proxy/S3ProxyHandler.java +++ b/src/main/java/org/gaul/s3proxy/S3ProxyHandler.java @@ -1775,9 +1775,12 @@ private void handleGetBlob(HttpServletRequest request, addCorsResponseHeader(request, response); addMetadataToResponse(request, response, blob.getMetadata()); + // TODO: handles only a single range due to jclouds limitations + var headers = new CaseInsensitiveImmutableMultimap( + blob.getAllHeaders()); Collection contentRanges = - blob.getAllHeaders().get(HttpHeaders.CONTENT_RANGE); + headers.get(HttpHeaders.CONTENT_RANGE); if (!contentRanges.isEmpty()) { response.addHeader(HttpHeaders.CONTENT_RANGE, contentRanges.iterator().next());