Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MINOR: Remove Dead Code from Netty4Transport #34134

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,6 @@ public static Netty4CorsConfigBuilder forAnyOrigin() {
return new Netty4CorsConfigBuilder();
}

/**
* Creates a {@link Netty4CorsConfigBuilder} instance with the specified origin.
*
* @return {@link Netty4CorsConfigBuilder} to support method chaining.
*/
public static Netty4CorsConfigBuilder forOrigin(final String origin) {
if ("*".equals(origin)) {
return new Netty4CorsConfigBuilder();
}
return new Netty4CorsConfigBuilder(origin);
}


/**
* Create a {@link Netty4CorsConfigBuilder} instance with the specified pattern origin.
*
Expand Down Expand Up @@ -94,7 +81,6 @@ public static Netty4CorsConfigBuilder forOrigins(final String... origins) {
final Set<HttpMethod> requestMethods = new HashSet<>();
final Set<String> requestHeaders = new HashSet<>();
final Map<CharSequence, Callable<?>> preflightHeaders = new HashMap<>();
private boolean noPreflightHeaders;
boolean shortCircuit;

/**
Expand Down Expand Up @@ -130,18 +116,6 @@ public static Netty4CorsConfigBuilder forOrigins(final String... origins) {
anyOrigin = false;
}

/**
* Web browsers may set the 'Origin' request header to 'null' if a resource is loaded
* from the local file system. Calling this method will enable a successful CORS response
* with a wildcard for the CORS response header 'Access-Control-Allow-Origin'.
*
* @return {@link Netty4CorsConfigBuilder} to support method chaining.
*/
Netty4CorsConfigBuilder allowNullOrigin() {
allowNullOrigin = true;
return this;
}

/**
* Disables CORS support.
*
Expand Down Expand Up @@ -219,71 +193,6 @@ public Netty4CorsConfigBuilder allowedRequestHeaders(final String... headers) {
return this;
}

/**
* Returns HTTP response headers that should be added to a CORS preflight response.
*
* An intermediary like a load balancer might require that a CORS preflight request
* have certain headers set. This enables such headers to be added.
*
* @param name the name of the HTTP header.
* @param values the values for the HTTP header.
* @return {@link Netty4CorsConfigBuilder} to support method chaining.
*/
public Netty4CorsConfigBuilder preflightResponseHeader(final CharSequence name, final Object... values) {
if (values.length == 1) {
preflightHeaders.put(name, new ConstantValueGenerator(values[0]));
} else {
preflightResponseHeader(name, Arrays.asList(values));
}
return this;
}

/**
* Returns HTTP response headers that should be added to a CORS preflight response.
*
* An intermediary like a load balancer might require that a CORS preflight request
* have certain headers set. This enables such headers to be added.
*
* @param name the name of the HTTP header.
* @param value the values for the HTTP header.
* @param <T> the type of values that the Iterable contains.
* @return {@link Netty4CorsConfigBuilder} to support method chaining.
*/
public <T> Netty4CorsConfigBuilder preflightResponseHeader(final CharSequence name, final Iterable<T> value) {
preflightHeaders.put(name, new ConstantValueGenerator(value));
return this;
}

/**
* Returns HTTP response headers that should be added to a CORS preflight response.
*
* An intermediary like a load balancer might require that a CORS preflight request
* have certain headers set. This enables such headers to be added.
*
* Some values must be dynamically created when the HTTP response is created, for
* example the 'Date' response header. This can be accomplished by using a Callable
* which will have its 'call' method invoked when the HTTP response is created.
*
* @param name the name of the HTTP header.
* @param valueGenerator a Callable which will be invoked at HTTP response creation.
* @param <T> the type of the value that the Callable can return.
* @return {@link Netty4CorsConfigBuilder} to support method chaining.
*/
public <T> Netty4CorsConfigBuilder preflightResponseHeader(final CharSequence name, final Callable<T> valueGenerator) {
preflightHeaders.put(name, valueGenerator);
return this;
}

/**
* Specifies that no preflight response headers should be added to a preflight response.
*
* @return {@link Netty4CorsConfigBuilder} to support method chaining.
*/
public Netty4CorsConfigBuilder noPreflightResponseHeaders() {
noPreflightHeaders = true;
return this;
}

/**
* Specifies that a CORS request should be rejected if it's invalid before being
* further processing.
Expand All @@ -305,7 +214,7 @@ public Netty4CorsConfigBuilder shortCircuit() {
* @return {@link Netty4CorsConfig} the configured CorsConfig instance.
*/
public Netty4CorsConfig build() {
if (preflightHeaders.isEmpty() && !noPreflightHeaders) {
if (preflightHeaders.isEmpty()) {
preflightHeaders.put("date", DateValueGenerator.INSTANCE);
preflightHeaders.put("content-length", new ConstantValueGenerator("0"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import io.netty.buffer.ByteBuf;
import io.netty.buffer.CompositeByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.util.NettyRuntime;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
Expand All @@ -34,7 +32,6 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down Expand Up @@ -133,27 +130,4 @@ static BytesReference toBytesReference(final ByteBuf buffer, final int size) {
return new ByteBufBytesReference(buffer, size);
}

public static void closeChannels(final Collection<Channel> channels) throws IOException {
IOException closingExceptions = null;
final List<ChannelFuture> futures = new ArrayList<>();
for (final Channel channel : channels) {
try {
if (channel != null && channel.isOpen()) {
futures.add(channel.close());
}
} catch (Exception e) {
if (closingExceptions == null) {
closingExceptions = new IOException("failed to close channels");
}
closingExceptions.addSuppressed(e);
}
}
for (final ChannelFuture future : futures) {
future.awaitUninterruptibly();
}

if (closingExceptions != null) {
throw closingExceptions;
}
}
}