Skip to content

Commit

Permalink
Inline & remove ChunkedRestResponseBody overrides (elastic#99875)
Browse files Browse the repository at this point in the history
Follow-up to elastic#99871 to inline and remove the deprecated overrides which
do not take a `Releasable` parameter.
  • Loading branch information
DaveCTurner authored Sep 25, 2023
1 parent dfec836 commit 5597c1d
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ public void dispatchRequest(final RestRequest request, final RestChannel channel
channel.sendResponse(
RestResponse.chunked(OK, ChunkedRestResponseBody.fromXContent(ignored -> Iterators.single((builder, params) -> {
throw new AssertionError("should not be called for HEAD REQUEST");
}), ToXContent.EMPTY_PARAMS, channel))
}), ToXContent.EMPTY_PARAMS, channel, null))
);
} catch (IOException e) {
throw new AssertionError(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,6 @@ public interface ChunkedRestResponseBody extends Releasable {
*/
String getResponseContentTypeString();

/**
* Create a chunked response body to be written to a specific {@link RestChannel} from a {@link ChunkedToXContent}.
*
* @param chunkedToXContent chunked x-content instance to serialize
* @param params parameters to use for serialization
* @param channel channel the response will be written to
* @return chunked rest response body
* @deprecated Use {@link #fromXContent(ChunkedToXContent, ToXContent.Params, RestChannel, Releasable)} instead.
*/
@Deprecated(forRemoval = true)
static ChunkedRestResponseBody fromXContent(ChunkedToXContent chunkedToXContent, ToXContent.Params params, RestChannel channel)
throws IOException {
return fromXContent(chunkedToXContent, params, channel, null);
}

/**
* Create a chunked response body to be written to a specific {@link RestChannel} from a {@link ChunkedToXContent}.
*
Expand Down Expand Up @@ -162,17 +147,6 @@ public void close() {
};
}

/**
* Create a chunked response body to be written to a specific {@link RestChannel} from a stream of text chunks, each represented as a
* consumer of a {@link Writer}. The last chunk that the iterator yields must write at least one byte.
*
* @deprecated Use {@link #fromTextChunks(String, Iterator, Releasable)} instead.
*/
@Deprecated(forRemoval = true)
static ChunkedRestResponseBody fromTextChunks(String contentType, Iterator<CheckedConsumer<Writer, IOException>> chunkIterator) {
return fromTextChunks(contentType, chunkIterator, null);
}

/**
* Create a chunked response body to be written to a specific {@link RestChannel} from a stream of text chunks, each represented as a
* consumer of a {@link Writer}. The last chunk that the iterator yields must write at least one byte.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public RestChunkedToXContentListener(RestChannel channel, ToXContent.Params para
@Override
protected void processResponse(Response response) throws IOException {
channel.sendResponse(
RestResponse.chunked(getRestStatus(response), ChunkedRestResponseBody.fromXContent(response, params, channel))
RestResponse.chunked(getRestStatus(response), ChunkedRestResponseBody.fromXContent(response, params, channel, null))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
return channel -> client.admin().cluster().nodesHotThreads(nodesHotThreadsRequest, new RestResponseListener<>(channel) {
@Override
public RestResponse buildResponse(NodesHotThreadsResponse response) {
return RestResponse.chunked(RestStatus.OK, fromTextChunks(TEXT_CONTENT_TYPE, response.getTextChunks()));
return RestResponse.chunked(RestStatus.OK, fromTextChunks(TEXT_CONTENT_TYPE, response.getTextChunks(), null));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public static RestResponse buildXContentBuilder(Table table, RestChannel channel
Iterators.single((builder, params) -> builder.endArray())
),
ToXContent.EMPTY_PARAMS,
channel
channel,
null
)
);
}
Expand Down Expand Up @@ -126,7 +127,8 @@ public static RestResponse buildTextPlainResponse(Table table, RestChannel chann
}
writer.append("\n");
})
)
),
null
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ public RestResponse buildResponse(NodesStatsResponse response) throws Exception
ChunkedToXContentHelper.endObject()
),
EMPTY_PARAMS,
channel
channel,
null
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void testWithHeaders() throws Exception {
public void testEmptyChunkedBody() {
RestResponse response = RestResponse.chunked(
RestStatus.OK,
ChunkedRestResponseBody.fromTextChunks(RestResponse.TEXT_CONTENT_TYPE, Collections.emptyIterator())
ChunkedRestResponseBody.fromTextChunks(RestResponse.TEXT_CONTENT_TYPE, Collections.emptyIterator(), null)
);
assertFalse(response.isChunked());
assertNotNull(response.content());
Expand Down

0 comments on commit 5597c1d

Please sign in to comment.