diff --git a/CHANGELOG.md b/CHANGELOG.md index f5c66eaa2702e..d93b68c56b636 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 \ No newline at end of file +[Unreleased 2.x]: https://github.com/opensearch-project/OpenSearch/compare/2.7...2.x diff --git a/server/src/main/java/org/opensearch/http/DefaultRestChannel.java b/server/src/main/java/org/opensearch/http/DefaultRestChannel.java index 9df59cbb6f377..3d2f194f78897 100644 --- a/server/src/main/java/org/opensearch/http/DefaultRestChannel.java +++ b/server/src/main/java/org/opensearch/http/DefaultRestChannel.java @@ -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; @@ -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; @@ -77,6 +79,7 @@ public class DefaultRestChannel extends AbstractRestChannel implements RestChann private final HttpChannel httpChannel; private final CorsHandler corsHandler; + @Nullable private final HttpTracer tracerLog; @@ -147,12 +150,25 @@ public void sendResponse(RestResponse restResponse) { addCustomHeaders(httpResponse, restResponse.getHeaders()); addCustomHeaders(httpResponse, threadContext.getResponseHeaders()); + Map> serverHeader = new HashMap<>(); + List 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();