Skip to content

Commit

Permalink
Use handlingSettings
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Perkins <[email protected]>
  • Loading branch information
cwperks committed Oct 2, 2023
1 parent b06242b commit e46adaa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ protected void initChannel(Channel ch) throws Exception {

@Override
protected ChannelInboundHandlerAdapter createHeaderVerifier() {
return new Netty4HttpRequestHeaderVerifier(restFilter, xContentRegistry, threadPool);
return new Netty4HttpRequestHeaderVerifier(restFilter, xContentRegistry, threadPool, handlingSettings);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.opensearch.http.AbstractHttpServerTransport;

import io.netty.channel.ChannelHandlerContext;
import org.opensearch.http.HttpHandlingSettings;
import org.opensearch.http.netty4.Netty4DefaultHttpRequest;
import org.opensearch.http.netty4.Netty4HttpChannel;
import org.opensearch.http.netty4.Netty4HttpServerTransport;
Expand All @@ -33,11 +34,18 @@ public class Netty4HttpRequestHeaderVerifier extends SimpleChannelInboundHandler
private final SecurityRestFilter restFilter;
private final ThreadPool threadPool;
private final NamedXContentRegistry xContentRegistry;
private final HttpHandlingSettings handlingSettings;

public Netty4HttpRequestHeaderVerifier(SecurityRestFilter restFilter, NamedXContentRegistry xContentRegistry, ThreadPool threadPool) {
public Netty4HttpRequestHeaderVerifier(
SecurityRestFilter restFilter,
NamedXContentRegistry xContentRegistry,
ThreadPool threadPool,
HttpHandlingSettings handlingSettings
) {
this.restFilter = restFilter;
this.xContentRegistry = xContentRegistry;
this.threadPool = threadPool;
this.handlingSettings = handlingSettings;
}

@Override
Expand All @@ -54,7 +62,10 @@ public void channelRead0(ChannelHandlerContext ctx, DefaultHttpRequest msg) thro
final Netty4DefaultHttpRequest httpRequest = new Netty4DefaultHttpRequest(msg);
RestRequest restRequest = AbstractHttpServerTransport.createRestRequest(xContentRegistry, httpRequest, httpChannel);

InterceptingRestChannel interceptingRestChannel = new InterceptingRestChannel(restRequest, false);
InterceptingRestChannel interceptingRestChannel = new InterceptingRestChannel(
restRequest,
handlingSettings.getDetailedErrorsEnabled()
);
ThreadContext threadContext = threadPool.getThreadContext();
try (ThreadContext.StoredContext ignore = threadPool.getThreadContext().stashContext()) {
boolean isUnauthenticated = restFilter.checkAndAuthenticateRequest(restRequest, interceptingRestChannel, threadContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,6 @@ protected void configurePipeline(Channel ch) {

@Override
protected ChannelInboundHandlerAdapter createHeaderVerifier() {
return new Netty4HttpRequestHeaderVerifier(restFilter, xContentRegistry, threadPool);
return new Netty4HttpRequestHeaderVerifier(restFilter, xContentRegistry, threadPool, handlingSettings);
}
}

0 comments on commit e46adaa

Please sign in to comment.