Skip to content

Commit

Permalink
Prefer immutable collections where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
gaul committed Aug 8, 2024
1 parent a3e6f47 commit 6a9778a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.regex.Matcher;
Expand All @@ -28,7 +29,6 @@
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -58,9 +58,9 @@ public final class CrossOriginResourceSharing {

public CrossOriginResourceSharing() {
// CORS Allow all
this(Lists.newArrayList(ALLOW_ANY_ORIGIN), SUPPORTED_METHODS,
Lists.newArrayList(ALLOW_ANY_HEADER),
Lists.newArrayList(EXPOSE_ALL_HEADERS), "");
this(List.of(ALLOW_ANY_ORIGIN), SUPPORTED_METHODS,
List.of(ALLOW_ANY_HEADER),
List.of(EXPOSE_ALL_HEADERS), "");
}

public CrossOriginResourceSharing(Collection<String> allowedOrigins,
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/org/gaul/s3proxy/S3Proxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;

import org.eclipse.jetty.http.HttpCompliance;
Expand Down Expand Up @@ -291,10 +292,11 @@ public static Builder fromProperties(Properties properties)
}

builder.corsRules(new CrossOriginResourceSharing(
Lists.newArrayList(splitter.split(corsAllowOrigins)),
Lists.newArrayList(splitter.split(corsAllowMethods)),
Lists.newArrayList(splitter.split(corsAllowHeaders)),
Lists.newArrayList(splitter.split(corsExposedHeaders)),
ImmutableList.copyOf(splitter.split(corsAllowOrigins)),
ImmutableList.copyOf(splitter.split(corsAllowMethods)),
ImmutableList.copyOf(splitter.split(corsAllowHeaders)),
ImmutableList.copyOf(splitter.split(
corsExposedHeaders)),
allowCredentials));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

import java.util.List;

import com.google.common.collect.Lists;

import org.junit.Before;
import org.junit.Test;

Expand All @@ -36,11 +34,11 @@ public void setUp() throws Exception {
corsAll = new CrossOriginResourceSharing();
// CORS Configured
corsCfg = new CrossOriginResourceSharing(
Lists.newArrayList("https://example\\.com",
List.of("https://example\\.com",
"https://.+\\.example\\.com",
"https://example\\.cloud"),
Lists.newArrayList("GET", "PUT"),
Lists.newArrayList("Accept", "Content-Type"),
List.of("GET", "PUT"),
List.of("Accept", "Content-Type"),
List.of(),
"true");
// CORS disabled
Expand Down

0 comments on commit 6a9778a

Please sign in to comment.