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

Added the addition of the server version and distribution as a respon… #8084

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4e2910a
Added server distribution and version into response header
Sam-ScottLogic Jun 16, 2023
1bc1e3d
Removed extra lines
Sam-ScottLogic Jun 16, 2023
1e218cb
Update server/src/main/java/org/opensearch/http/DefaultRestChannel.java
Sam-ScottLogic Jun 16, 2023
d24139b
Moved defining of server header string
Sam-ScottLogic Jun 16, 2023
00dadc7
Removed wildcard import
Sam-ScottLogic Jun 19, 2023
d16008c
Applied spotless to files
Sam-ScottLogic Jun 20, 2023
2b63355
Added to testHeadersSet test within the default rest channel test fil…
Sam-ScottLogic Jun 20, 2023
a0fee36
Ran spotless
Sam-ScottLogic Jun 20, 2023
bac79db
Added comment
Sam-ScottLogic Jun 27, 2023
fb30d86
Merge branch 'main' into feature/return_a_server_header_with_server_v…
Sam-ScottLogic Jun 28, 2023
8299b6f
Created static string for reused server header title and name of appl…
Sam-ScottLogic Jun 29, 2023
d1cc7c5
Refactored hash map from server header to server version and updated …
Sam-ScottLogic Jun 29, 2023
fb2ea8c
Ran spotless
Sam-ScottLogic Jun 29, 2023
3254b5b
Merge branch 'main' into feature/return_a_server_header_with_server_v…
Sam-ScottLogic Jun 29, 2023
8537e22
Moved server version field from global variable to local, defined sev…
Sam-ScottLogic Jun 29, 2023
f96fc2d
Added prefix to header title
Sam-ScottLogic Jun 29, 2023
9f65b3c
Removed redundant serverVersion field and instead inlined creation of…
Sam-ScottLogic Jun 29, 2023
04ed8fe
Ran spotless
Sam-ScottLogic Jun 29, 2023
a34147c
Removed redundant OPEN_SEARCH_NAME_VALUE
Sam-ScottLogic Jun 29, 2023
c887a0e
Update server/src/test/java/org/opensearch/http/DefaultRestChannelTes…
Sam-ScottLogic Jun 30, 2023
ec0876f
Moved change log addition to 2.x unreleased and wrote message in impe…
Sam-ScottLogic Jul 10, 2023
1f43b86
Corrected name of fetched header in header test
Sam-ScottLogic Jul 10, 2023
5163a7f
Merged main
Sam-ScottLogic Jul 10, 2023
6b00d4d
Merge branch 'feature/return_a_server_header_with_server_version' of …
Sam-ScottLogic Jul 10, 2023
9b0709b
Merged main
Sam-ScottLogic Jul 11, 2023
fc1abac
Added server version header value as constant
Sam-ScottLogic Jul 12, 2023
0a3ece5
Merged main
Sam-ScottLogic Jul 13, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Create concept of persistent ThreadContext headers that are unstashable ([#8291]()https://github.com/opensearch-project/OpenSearch/pull/8291)
- [Search pipelines] Add Global Ignore_failure options for Processors ([#8373](https://github.com/opensearch-project/OpenSearch/pull/8373))
- Enable Partial Flat Object ([#7997](https://github.com/opensearch-project/OpenSearch/pull/7997))
- Add server version as REST response header [#6583](https://github.com/opensearch-project/OpenSearch/issues/6583)
- Add jdk.incubator.vector module support for JDK 20+ ([#8601](https://github.com/opensearch-project/OpenSearch/pull/8601))
- Introduce full support for Search Pipeline ([#8613](https://github.com/opensearch-project/OpenSearch/pull/8613))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

package org.opensearch.http;

import org.opensearch.Build;
import org.opensearch.action.ActionListener;
import org.opensearch.common.Nullable;
import org.opensearch.core.common.bytes.BytesArray;
Expand All @@ -48,7 +49,6 @@
import org.opensearch.rest.RestRequest;
import org.opensearch.rest.RestResponse;
import org.opensearch.core.rest.RestStatus;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand All @@ -69,13 +69,20 @@ public class DefaultRestChannel extends AbstractRestChannel implements RestChann
static final String CONTENT_TYPE = "content-type";
static final String CONTENT_LENGTH = "content-length";
static final String SET_COOKIE = "set-cookie";
static final String SERVER_VERSION = "X-OpenSearch-Version";
static final String SERVER_VERSION_VALUE = "OpenSearch/"
+ Build.CURRENT.getQualifiedVersion()
+ " ("
+ Build.CURRENT.getDistribution()
+ ")";

private final HttpRequest httpRequest;
private final BigArrays bigArrays;
private final HttpHandlingSettings settings;
private final ThreadContext threadContext;
private final HttpChannel httpChannel;
private final CorsHandler corsHandler;
private final Map<String, List<String>> SERVER_VERSION_HEADER = Map.of(SERVER_VERSION, List.of(SERVER_VERSION_VALUE));

@Nullable
private final HttpTracer tracerLog;
Expand Down Expand Up @@ -147,6 +154,8 @@ public void sendResponse(RestResponse restResponse) {
addCustomHeaders(httpResponse, restResponse.getHeaders());
addCustomHeaders(httpResponse, threadContext.getResponseHeaders());

addCustomHeaders(httpResponse, SERVER_VERSION_HEADER);

// If our response doesn't specify a content-type header, set one
setHeaderField(httpResponse, CONTENT_TYPE, restResponse.contentType(), false);
// If our response has no content-length, calculate and set one
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

package org.opensearch.http;

import org.opensearch.Build;
import org.opensearch.action.ActionListener;
import org.opensearch.core.common.bytes.BytesArray;
import org.opensearch.core.common.bytes.BytesReference;
Expand Down Expand Up @@ -189,6 +190,10 @@ public void testHeadersSet() {
assertEquals("abc", headers.get(Task.X_OPAQUE_ID).get(0));
assertEquals(Integer.toString(resp.content().length()), headers.get(DefaultRestChannel.CONTENT_LENGTH).get(0));
assertEquals(resp.contentType(), headers.get(DefaultRestChannel.CONTENT_TYPE).get(0));
assertEquals(
"OpenSearch/" + Build.CURRENT.getQualifiedVersion() + " (" + Build.CURRENT.getDistribution() + ")",
headers.get("X-OpenSearch-Version").get(0)
);
}

public void testCookiesSet() {
Expand Down