mattbaird / elastigo

A Go (golang) based Elasticsearch client library.
Apache License 2.0
943 stars 241 forks source link

gzipped requests omit content-type header #295

Open ththvseo opened 6 years ago

ththvseo commented 6 years ago

we are seeing lots of: [WARN][RestController ] Content type detection for rest requests is deprecated. Specify the content type using the [Content-Type] header. from elasticsearch.

it is probably a general issue that the header is not added, especially for non-json payloads,

but spefically the code for gzip compression, as introduced here: https://github.com/mattbaird/elastigo/pull/263/files omits setting the Content-Type header. unlike the pre-existing SetBodyJson(), the newly added SetBodyGzip() is missing the logic for setting that header. a quick solution should be to add the header when generating json, as in SetBodyJson():

    switch v := data.(type) {
    default:
             b, err := json.Marshal(data)
+           r.Header.Set("Content-Type", "application/json")