Skip to content

Commit 04a495a

Browse files
original-brownbearkcm
authored andcommitted
MINOR: Remove Dead Code from Netty4Transport (#34134)
* None of these methods are used
1 parent 0aa0b95 commit 04a495a

File tree

2 files changed

+1
-118
lines changed

2 files changed

+1
-118
lines changed

modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/cors/Netty4CorsConfigBuilder.java

Lines changed: 1 addition & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,6 @@ public static Netty4CorsConfigBuilder forAnyOrigin() {
4949
return new Netty4CorsConfigBuilder();
5050
}
5151

52-
/**
53-
* Creates a {@link Netty4CorsConfigBuilder} instance with the specified origin.
54-
*
55-
* @return {@link Netty4CorsConfigBuilder} to support method chaining.
56-
*/
57-
public static Netty4CorsConfigBuilder forOrigin(final String origin) {
58-
if ("*".equals(origin)) {
59-
return new Netty4CorsConfigBuilder();
60-
}
61-
return new Netty4CorsConfigBuilder(origin);
62-
}
63-
64-
6552
/**
6653
* Create a {@link Netty4CorsConfigBuilder} instance with the specified pattern origin.
6754
*
@@ -94,7 +81,6 @@ public static Netty4CorsConfigBuilder forOrigins(final String... origins) {
9481
final Set<HttpMethod> requestMethods = new HashSet<>();
9582
final Set<String> requestHeaders = new HashSet<>();
9683
final Map<CharSequence, Callable<?>> preflightHeaders = new HashMap<>();
97-
private boolean noPreflightHeaders;
9884
boolean shortCircuit;
9985

10086
/**
@@ -130,18 +116,6 @@ public static Netty4CorsConfigBuilder forOrigins(final String... origins) {
130116
anyOrigin = false;
131117
}
132118

133-
/**
134-
* Web browsers may set the 'Origin' request header to 'null' if a resource is loaded
135-
* from the local file system. Calling this method will enable a successful CORS response
136-
* with a wildcard for the CORS response header 'Access-Control-Allow-Origin'.
137-
*
138-
* @return {@link Netty4CorsConfigBuilder} to support method chaining.
139-
*/
140-
Netty4CorsConfigBuilder allowNullOrigin() {
141-
allowNullOrigin = true;
142-
return this;
143-
}
144-
145119
/**
146120
* Disables CORS support.
147121
*
@@ -219,71 +193,6 @@ public Netty4CorsConfigBuilder allowedRequestHeaders(final String... headers) {
219193
return this;
220194
}
221195

222-
/**
223-
* Returns HTTP response headers that should be added to a CORS preflight response.
224-
*
225-
* An intermediary like a load balancer might require that a CORS preflight request
226-
* have certain headers set. This enables such headers to be added.
227-
*
228-
* @param name the name of the HTTP header.
229-
* @param values the values for the HTTP header.
230-
* @return {@link Netty4CorsConfigBuilder} to support method chaining.
231-
*/
232-
public Netty4CorsConfigBuilder preflightResponseHeader(final CharSequence name, final Object... values) {
233-
if (values.length == 1) {
234-
preflightHeaders.put(name, new ConstantValueGenerator(values[0]));
235-
} else {
236-
preflightResponseHeader(name, Arrays.asList(values));
237-
}
238-
return this;
239-
}
240-
241-
/**
242-
* Returns HTTP response headers that should be added to a CORS preflight response.
243-
*
244-
* An intermediary like a load balancer might require that a CORS preflight request
245-
* have certain headers set. This enables such headers to be added.
246-
*
247-
* @param name the name of the HTTP header.
248-
* @param value the values for the HTTP header.
249-
* @param <T> the type of values that the Iterable contains.
250-
* @return {@link Netty4CorsConfigBuilder} to support method chaining.
251-
*/
252-
public <T> Netty4CorsConfigBuilder preflightResponseHeader(final CharSequence name, final Iterable<T> value) {
253-
preflightHeaders.put(name, new ConstantValueGenerator(value));
254-
return this;
255-
}
256-
257-
/**
258-
* Returns HTTP response headers that should be added to a CORS preflight response.
259-
*
260-
* An intermediary like a load balancer might require that a CORS preflight request
261-
* have certain headers set. This enables such headers to be added.
262-
*
263-
* Some values must be dynamically created when the HTTP response is created, for
264-
* example the 'Date' response header. This can be accomplished by using a Callable
265-
* which will have its 'call' method invoked when the HTTP response is created.
266-
*
267-
* @param name the name of the HTTP header.
268-
* @param valueGenerator a Callable which will be invoked at HTTP response creation.
269-
* @param <T> the type of the value that the Callable can return.
270-
* @return {@link Netty4CorsConfigBuilder} to support method chaining.
271-
*/
272-
public <T> Netty4CorsConfigBuilder preflightResponseHeader(final CharSequence name, final Callable<T> valueGenerator) {
273-
preflightHeaders.put(name, valueGenerator);
274-
return this;
275-
}
276-
277-
/**
278-
* Specifies that no preflight response headers should be added to a preflight response.
279-
*
280-
* @return {@link Netty4CorsConfigBuilder} to support method chaining.
281-
*/
282-
public Netty4CorsConfigBuilder noPreflightResponseHeaders() {
283-
noPreflightHeaders = true;
284-
return this;
285-
}
286-
287196
/**
288197
* Specifies that a CORS request should be rejected if it's invalid before being
289198
* further processing.
@@ -305,7 +214,7 @@ public Netty4CorsConfigBuilder shortCircuit() {
305214
* @return {@link Netty4CorsConfig} the configured CorsConfig instance.
306215
*/
307216
public Netty4CorsConfig build() {
308-
if (preflightHeaders.isEmpty() && !noPreflightHeaders) {
217+
if (preflightHeaders.isEmpty()) {
309218
preflightHeaders.put("date", DateValueGenerator.INSTANCE);
310219
preflightHeaders.put("content-length", new ConstantValueGenerator("0"));
311220
}

modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Utils.java

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
import io.netty.buffer.ByteBuf;
2323
import io.netty.buffer.CompositeByteBuf;
2424
import io.netty.buffer.Unpooled;
25-
import io.netty.channel.Channel;
26-
import io.netty.channel.ChannelFuture;
2725
import io.netty.util.NettyRuntime;
2826
import io.netty.util.internal.logging.InternalLogger;
2927
import io.netty.util.internal.logging.InternalLoggerFactory;
@@ -34,7 +32,6 @@
3432

3533
import java.io.IOException;
3634
import java.util.ArrayList;
37-
import java.util.Collection;
3835
import java.util.List;
3936
import java.util.Locale;
4037
import java.util.concurrent.atomic.AtomicBoolean;
@@ -133,27 +130,4 @@ static BytesReference toBytesReference(final ByteBuf buffer, final int size) {
133130
return new ByteBufBytesReference(buffer, size);
134131
}
135132

136-
public static void closeChannels(final Collection<Channel> channels) throws IOException {
137-
IOException closingExceptions = null;
138-
final List<ChannelFuture> futures = new ArrayList<>();
139-
for (final Channel channel : channels) {
140-
try {
141-
if (channel != null && channel.isOpen()) {
142-
futures.add(channel.close());
143-
}
144-
} catch (Exception e) {
145-
if (closingExceptions == null) {
146-
closingExceptions = new IOException("failed to close channels");
147-
}
148-
closingExceptions.addSuppressed(e);
149-
}
150-
}
151-
for (final ChannelFuture future : futures) {
152-
future.awaitUninterruptibly();
153-
}
154-
155-
if (closingExceptions != null) {
156-
throw closingExceptions;
157-
}
158-
}
159133
}

0 commit comments

Comments
 (0)