Skip to content

Commit

Permalink
Added server distribution and version into response header
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Hobbs <[email protected]>
  • Loading branch information
Sam-ScottLogic committed Jun 16, 2023
1 parent a201400 commit 3da7ec7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Allow mmap to use new JDK-19 preview APIs in Apache Lucene 9.4+ ([#5151](https://github.com/opensearch-project/OpenSearch/pull/5151))
- Add events correlation engine plugin ([#6854](https://github.com/opensearch-project/OpenSearch/issues/6854))
- Add support for ignoring missing Javadoc on generated code using annotation ([#7604](https://github.com/opensearch-project/OpenSearch/pull/7604))

- Added server version as response header [#6583](https://github.com/opensearch-project/OpenSearch/issues/6583)
### Dependencies
- Bump `log4j-core` from 2.18.0 to 2.19.0
- Bump `forbiddenapis` from 3.3 to 3.4
Expand Down Expand Up @@ -154,4 +154,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Security

[Unreleased 3.0]: https://github.com/opensearch-project/OpenSearch/compare/2.x...HEAD
[Unreleased 2.x]: https://github.com/opensearch-project/OpenSearch/compare/2.7...2.x
[Unreleased 2.x]: https://github.com/opensearch-project/OpenSearch/compare/2.7...2.x
16 changes: 16 additions & 0 deletions server/src/main/java/org/opensearch/http/DefaultRestChannel.java
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.common.bytes.BytesArray;
Expand All @@ -50,6 +51,7 @@
import org.opensearch.rest.RestStatus;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -77,6 +79,7 @@ public class DefaultRestChannel extends AbstractRestChannel implements RestChann
private final HttpChannel httpChannel;
private final CorsHandler corsHandler;


@Nullable
private final HttpTracer tracerLog;

Expand Down Expand Up @@ -147,12 +150,25 @@ public void sendResponse(RestResponse restResponse) {
addCustomHeaders(httpResponse, restResponse.getHeaders());
addCustomHeaders(httpResponse, threadContext.getResponseHeaders());

Map<String, List<String>> serverHeader = new HashMap<>();
List<String> serverHeaderString = new ArrayList<>();

serverHeaderString.add("OpenSearch/" + Build.CURRENT.getQualifiedVersion() + " (" + Build.CURRENT.getDistribution() + ")");

serverHeader.put("serverHeader", serverHeaderString);

addCustomHeaders(httpResponse, serverHeader);

// 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
contentLength = String.valueOf(restResponse.content().length());
setHeaderField(httpResponse, CONTENT_LENGTH, contentLength, false);





addCookies(httpResponse);

BytesStreamOutput bytesStreamOutput = bytesOutputOrNull();
Expand Down

0 comments on commit 3da7ec7

Please sign in to comment.