Skip to content

Commit

Permalink
Change Content-Type header to be Kibana 7 compatible (#983)
Browse files Browse the repository at this point in the history
Closes: #994
  • Loading branch information
mieciu authored Nov 18, 2024
1 parent 740da42 commit 864c8ba
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
17 changes: 8 additions & 9 deletions quesma/quesma/http_headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package quesma

import (
"net/http"
"quesma/logger"
"slices"
)

Expand Down Expand Up @@ -36,18 +35,18 @@ func addProductAndContentHeaders(request http.Header, response http.Header) {
response.Set(contentTypeHeaderKey, "application/json; charset=UTF-8")
} else {
response.Set(elasticSearchResponseHeaderKey, elasticSearchResponseHeaderValue)
response.Set(contentTypeHeaderKey, "application/vnd.elasticsearch+json;compatible-with=8")
//response.Set(contentTypeHeaderKey, "application/vnd.elasticsearch+json;compatible-with=8")
}
// WARNING:
// Elasticsearch 8.x responds with `Content-Type: application/vnd.elasticsearch+json;compatible-with=8`
// Elasticsearch 7.x responds with `Content-Type: application/json; charset=UTF-8`
// We decided to always use the 7.x response for now, but we might need to change it in the future.
// Specifically, we might need to change this behaviour by introducing Elasticsearch 8 and Elasticsearch 7-specific frontend connectors.
// More in: https://github.com/QuesmaOrg/quesma/issues/994
response.Set(contentTypeHeaderKey, "application/json; charset=UTF-8")
response.Set(opaqueIdHeaderKey, "unknownId")
}

func LogMissingEsHeaders(elasticsearchHeaders, quesmaHeaders http.Header, reqId string) {
missingHeaders := findMissingElasticsearchHeaders(elasticsearchHeaders, quesmaHeaders)
for _, headerName := range missingHeaders {
logger.Warn().Str(logger.RID, reqId).Msgf("Header %s is missing in Quesma's response", headerName)
}
}

func findMissingElasticsearchHeaders(elasticsearchHeaders, quesmaHeaders http.Header) []string {
var missingHeaders []string
for esHeaderName := range elasticsearchHeaders {
Expand Down
2 changes: 1 addition & 1 deletion quesma/quesma/http_headers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func Test_EsHeaders(t *testing.T) {
response = make(http.Header)
addProductAndContentHeaders(request, response)
assert.Equal(t, elasticSearchResponseHeaderValue, response.Get(elasticSearchResponseHeaderKey), "X-Elastic-Product set correctly")
assert.Equalf(t, "application/vnd.elasticsearch+json;compatible-with=8", response.Get(contentTypeHeaderKey), "Content-Type set correctly")
assert.Equalf(t, "application/json; charset=UTF-8", response.Get(contentTypeHeaderKey), "Content-Type set correctly")
}

func TestFindMissingElasticsearchHeaders(t *testing.T) {
Expand Down

0 comments on commit 864c8ba

Please sign in to comment.