Skip to content

Commit

Permalink
Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim-Brooks committed Sep 19, 2024
1 parent 46dd1fd commit fa084dc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.http.HttpBody;
import org.elasticsearch.http.HttpPreRequest;
import org.elasticsearch.http.HttpRequest;
import org.elasticsearch.http.HttpResponse;
import org.elasticsearch.rest.ChunkedRestResponseBodyPart;
Expand All @@ -48,6 +49,7 @@ public class Netty4HttpRequest implements HttpRequest {
private final Exception inboundException;
private final boolean pooled;
private final int sequence;
private final String rawPath;

Netty4HttpRequest(int sequence, io.netty.handler.codec.http.HttpRequest request, Netty4HttpRequestBodyStream contentStream) {
this(
Expand Down Expand Up @@ -94,6 +96,7 @@ private Netty4HttpRequest(
this.pooled = pooled;
this.released = released;
this.inboundException = inboundException;
this.rawPath = HttpPreRequest.extractPathFromUri(uri());
}

@Override
Expand All @@ -106,6 +109,11 @@ public String uri() {
return request.uri();
}

@Override
public String rawPath() {
return rawPath;
}

@Override
public HttpBody body() {
assert released.get() == false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,7 @@ protected HttpMessage createMessage(String[] initialLine) throws Exception {
// combines the HTTP message pieces into a single full HTTP request (with headers and body)
final HttpObjectAggregator aggregator = new Netty4HttpAggregator(
handlingSettings.maxContentLength(),
httpPreRequest -> enabled.get() == false
|| (httpPreRequest.uri().contains("_bulk") == false
|| httpPreRequest.uri().contains("_bulk_update")
|| httpPreRequest.uri().contains("/_xpack/monitoring/_bulk"))
httpPreRequest -> enabled.get() == false || (httpPreRequest.rawPath().endsWith("/_bulk") == false)
);
aggregator.setMaxCumulationBufferComponents(transport.maxCompositeBufferComponents);
ch.pipeline()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ public interface HttpPreRequest {
/**
* The uri without the query string.
*/
default String path() {
String uri = uri();
default String rawPath() {
return extractPathFromUri(uri());
}

static String extractPathFromUri(String uri) {
final int index = uri.indexOf('?');
if (index >= 0) {
return uri.substring(0, index);
Expand Down
11 changes: 5 additions & 6 deletions server/src/main/java/org/elasticsearch/rest/RestRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,19 @@ public boolean isContentConsumed() {
protected RestRequest(
XContentParserConfiguration parserConfig,
Map<String, String> params,
String path,
String rawPath,
Map<String, List<String>> headers,
HttpRequest httpRequest,
HttpChannel httpChannel
) {
this(parserConfig, params, path, headers, httpRequest, httpChannel, requestIdGenerator.incrementAndGet());
this(parserConfig, params, rawPath, headers, httpRequest, httpChannel, requestIdGenerator.incrementAndGet());
}

@SuppressWarnings("this-escape")
private RestRequest(
XContentParserConfiguration parserConfig,
Map<String, String> params,
String path,
String rawPath,
Map<String, List<String>> headers,
HttpRequest httpRequest,
HttpChannel httpChannel,
Expand Down Expand Up @@ -149,7 +149,7 @@ private RestRequest(
: parserConfig.withRestApiVersion(effectiveApiVersion);
this.httpChannel = httpChannel;
this.params = params;
this.rawPath = path;
this.rawPath = rawPath;
this.headers = Collections.unmodifiableMap(headers);
this.requestId = requestId;
}
Expand Down Expand Up @@ -204,11 +204,10 @@ void ensureSafeBuffers() {
*/
public static RestRequest request(XContentParserConfiguration parserConfig, HttpRequest httpRequest, HttpChannel httpChannel) {
Map<String, String> params = params(httpRequest.uri());
String path = httpRequest.path();
return new RestRequest(
parserConfig,
params,
path,
httpRequest.rawPath(),
httpRequest.getHeaders(),
httpRequest,
httpChannel,
Expand Down

0 comments on commit fa084dc

Please sign in to comment.