Skip to content

Commit 43c7f92

Browse files
committed
Use standard MIME types for content-type and accept headers
1 parent 4fa6c12 commit 43c7f92

File tree

3 files changed

+20
-40
lines changed

3 files changed

+20
-40
lines changed

src/client.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,7 @@ export default class Client extends API {
241241
context: options.context,
242242
productCheck: 'Elasticsearch',
243243
maxResponseSize: options.maxResponseSize,
244-
maxCompressedResponseSize: options.maxCompressedResponseSize,
245-
vendoredHeaders: {
246-
jsonContentType: 'application/vnd.elasticsearch+json; compatible-with=8',
247-
ndjsonContentType: 'application/vnd.elasticsearch+x-ndjson; compatible-with=8',
248-
accept: 'application/vnd.elasticsearch+json; compatible-with=8,text/plain'
249-
}
244+
maxCompressedResponseSize: options.maxCompressedResponseSize
250245
})
251246

252247
this.helpers = new Helpers({

test/integration/test-runner.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -288,21 +288,6 @@ function build (opts = {}) {
288288
process.exit(1)
289289
}
290290

291-
if (action.headers) {
292-
switch (action.headers['Content-Type'] || action.headers['content-type']) {
293-
case 'application/json':
294-
delete action.headers['Content-Type']
295-
delete action.headers['content-type']
296-
action.headers['Content-Type'] = `application/vnd.elasticsearch+json; compatible-with=${packageJson.version.split('.')[0]}`
297-
break
298-
case 'application/x-ndjson':
299-
delete action.headers['Content-Type']
300-
delete action.headers['content-type']
301-
action.headers['Content-Type'] = `application/vnd.elasticsearch+x-ndjson; compatible-with=${packageJson.version.split('.')[0]}`
302-
break
303-
}
304-
}
305-
306291
const options = { ignore: cmd.params.ignore, headers: action.headers, meta: true }
307292
if (!Array.isArray(options.ignore)) options.ignore = [options.ignore]
308293
if (cmd.params.ignore) delete cmd.params.ignore

test/unit/helpers/bulk.test.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ test('bulk index', t => {
5656
onRequest (params) {
5757
t.equal(params.path, '/_bulk')
5858
t.match(params.headers, {
59-
'content-type': 'application/vnd.elasticsearch+x-ndjson; compatible-with=8',
59+
'content-type': 'application/x-ndjson',
6060
'x-elastic-client-meta': `esv=${clientVersionNoMeta},js=${nodeVersion},t=${transportVersion},hc=${nodeVersion},h=bp`
6161
})
6262
// @ts-expect-error
@@ -103,7 +103,7 @@ test('bulk index', t => {
103103
const MockConnection = connection.buildMockConnection({
104104
onRequest (params) {
105105
t.equal(params.path, '/_bulk')
106-
t.match(params.headers, { 'content-type': 'application/vnd.elasticsearch+x-ndjson; compatible-with=8' })
106+
t.match(params.headers, { 'content-type': 'application/x-ndjson' })
107107
t.notMatch(params.headers, {
108108
'x-elastic-client-meta': `esv=${clientVersionNoMeta},js=${nodeVersion},t=${transportVersion},hc=${nodeVersion},h=bp`
109109
})
@@ -150,7 +150,7 @@ test('bulk index', t => {
150150
const MockConnection = connection.buildMockConnection({
151151
onRequest (params) {
152152
t.equal(params.path, '/_bulk')
153-
t.match(params.headers, { 'content-type': 'application/vnd.elasticsearch+x-ndjson; compatible-with=8' })
153+
t.match(params.headers, { 'content-type': 'application/x-ndjson' })
154154
// @ts-expect-error
155155
t.equal(params.body.split('\n').filter(Boolean).length, 6)
156156
return { body: { errors: false, items: new Array(3).fill({}) } }
@@ -192,7 +192,7 @@ test('bulk index', t => {
192192
const MockConnection = connection.buildMockConnection({
193193
onRequest (params) {
194194
t.equal(params.path, '/_bulk')
195-
t.match(params.headers, { 'content-type': 'application/vnd.elasticsearch+x-ndjson; compatible-with=8' })
195+
t.match(params.headers, { 'content-type': 'application/x-ndjson' })
196196
// @ts-expect-error
197197
const [action, payload] = params.body.split('\n')
198198
t.same(JSON.parse(action), { index: { _index: 'test', _id: count } })
@@ -238,7 +238,7 @@ test('bulk index', t => {
238238
t.test('Should perform a bulk request (retry)', async t => {
239239
async function handler (req: http.IncomingMessage, res: http.ServerResponse) {
240240
t.equal(req.url, '/_bulk')
241-
t.match(req.headers, { 'content-type': 'application/vnd.elasticsearch+x-ndjson; compatible-with=8' })
241+
t.match(req.headers, { 'content-type': 'application/x-ndjson' })
242242

243243
let body = ''
244244
req.setEncoding('utf8')
@@ -359,7 +359,7 @@ test('bulk index', t => {
359359
t.test('Should perform a bulk request (failure)', async t => {
360360
async function handler (req: http.IncomingMessage, res: http.ServerResponse) {
361361
t.equal(req.url, '/_bulk')
362-
t.match(req.headers, { 'content-type': 'application/vnd.elasticsearch+x-ndjson; compatible-with=8' })
362+
t.match(req.headers, { 'content-type': 'application/x-ndjson' })
363363

364364
let body = ''
365365
req.setEncoding('utf8')
@@ -503,7 +503,7 @@ test('bulk index', t => {
503503
t.test('Should abort a bulk request', async t => {
504504
async function handler (req: http.IncomingMessage, res: http.ServerResponse) {
505505
t.equal(req.url, '/_bulk')
506-
t.match(req.headers, { 'content-type': 'application/vnd.elasticsearch+x-ndjson; compatible-with=8' })
506+
t.match(req.headers, { 'content-type': 'application/x-ndjson' })
507507

508508
let body = ''
509509
req.setEncoding('utf8')
@@ -606,7 +606,7 @@ test('bulk index', t => {
606606
const MockConnection = connection.buildMockConnection({
607607
onRequest (params) {
608608
t.equal(params.path, '/_bulk')
609-
t.match(params.headers, { 'content-type': 'application/vnd.elasticsearch+x-ndjson; compatible-with=8' })
609+
t.match(params.headers, { 'content-type': 'application/x-ndjson' })
610610
// @ts-expect-error
611611
const [action, payload] = params.body.split('\n')
612612
t.same(JSON.parse(action), { index: { _index: 'test', _id: count } })
@@ -660,7 +660,7 @@ test('bulk index', t => {
660660
const MockConnection = connection.buildMockConnection({
661661
onRequest (params) {
662662
t.equal(params.path, '/_bulk')
663-
t.match(params.headers, { 'content-type': 'application/vnd.elasticsearch+x-ndjson; compatible-with=8' })
663+
t.match(params.headers, { 'content-type': 'application/x-ndjson' })
664664
// @ts-expect-error
665665
const [action, payload] = params.body.split('\n')
666666
t.same(JSON.parse(action), { index: { _index: 'test' } })
@@ -718,7 +718,7 @@ test('bulk create', t => {
718718
const MockConnection = connection.buildMockConnection({
719719
onRequest (params) {
720720
t.equal(params.path, '/_bulk')
721-
t.match(params.headers, { 'content-type': 'application/vnd.elasticsearch+x-ndjson; compatible-with=8' })
721+
t.match(params.headers, { 'content-type': 'application/x-ndjson' })
722722
// @ts-expect-error
723723
const [action, payload] = params.body.split('\n')
724724
t.same(JSON.parse(action), { create: { _index: 'test', _id: count } })
@@ -769,7 +769,7 @@ test('bulk update', t => {
769769
const MockConnection = connection.buildMockConnection({
770770
onRequest (params) {
771771
t.equal(params.path, '/_bulk')
772-
t.match(params.headers, { 'content-type': 'application/vnd.elasticsearch+x-ndjson; compatible-with=8' })
772+
t.match(params.headers, { 'content-type': 'application/x-ndjson' })
773773
// @ts-expect-error
774774
const [action, payload] = params.body.split('\n')
775775
t.same(JSON.parse(action), { update: { _index: 'test', _id: count } })
@@ -819,7 +819,7 @@ test('bulk update', t => {
819819
const MockConnection = connection.buildMockConnection({
820820
onRequest (params) {
821821
t.equal(params.path, '/_bulk')
822-
t.match(params.headers, { 'content-type': 'application/vnd.elasticsearch+x-ndjson; compatible-with=8' })
822+
t.match(params.headers, { 'content-type': 'application/x-ndjson' })
823823
// @ts-expect-error
824824
const [action, payload] = params.body.split('\n')
825825
t.same(JSON.parse(action), { update: { _index: 'test', _id: count } })
@@ -867,7 +867,7 @@ test('bulk update', t => {
867867
const MockConnection = connection.buildMockConnection({
868868
onRequest (params) {
869869
t.equal(params.path, '/_bulk')
870-
t.match(params.headers, { 'content-type': 'application/vnd.elasticsearch+x-ndjson; compatible-with=8' })
870+
t.match(params.headers, { 'content-type': 'application/x-ndjson' })
871871
// @ts-expect-error
872872
const [action, payload] = params.body.split('\n')
873873
t.same(JSON.parse(action), { update: { _index: 'test', _id: count } })
@@ -922,7 +922,7 @@ test('bulk delete', t => {
922922
const MockConnection = connection.buildMockConnection({
923923
onRequest (params) {
924924
t.equal(params.path, '/_bulk')
925-
t.match(params.headers, { 'content-type': 'application/vnd.elasticsearch+x-ndjson; compatible-with=8' })
925+
t.match(params.headers, { 'content-type': 'application/x-ndjson' })
926926
// @ts-expect-error
927927
t.same(JSON.parse(params.body), { delete: { _index: 'test', _id: count++ } })
928928
return { body: { errors: false, items: [{}] } }
@@ -966,7 +966,7 @@ test('bulk delete', t => {
966966
t.test('Should perform a bulk request (failure)', async t => {
967967
async function handler (req: http.IncomingMessage, res: http.ServerResponse) {
968968
t.equal(req.url, '/_bulk')
969-
t.match(req.headers, { 'content-type': 'application/vnd.elasticsearch+x-ndjson; compatible-with=8' })
969+
t.match(req.headers, { 'content-type': 'application/x-ndjson' })
970970

971971
let body = ''
972972
req.setEncoding('utf8')
@@ -1115,7 +1115,7 @@ test('transport options', t => {
11151115

11161116
if (params.path === '/_bulk') {
11171117
t.match(params.headers, {
1118-
'content-type': 'application/vnd.elasticsearch+x-ndjson; compatible-with=8',
1118+
'content-type': 'application/x-ndjson',
11191119
foo: 'bar'
11201120
})
11211121
return { body: { errors: false, items: [{}] } }
@@ -1231,7 +1231,7 @@ test('Flush interval', t => {
12311231
const MockConnection = connection.buildMockConnection({
12321232
onRequest (params) {
12331233
t.equal(params.path, '/_bulk')
1234-
t.match(params.headers, { 'content-type': 'application/vnd.elasticsearch+x-ndjson; compatible-with=8' })
1234+
t.match(params.headers, { 'content-type': 'application/x-ndjson' })
12351235
// @ts-expect-error
12361236
const [action, payload] = params.body.split('\n')
12371237
t.same(JSON.parse(action), { index: { _index: 'test' } })
@@ -1285,7 +1285,7 @@ test('Flush interval', t => {
12851285
onRequest (params) {
12861286
t.ok(count < 2)
12871287
t.equal(params.path, '/_bulk')
1288-
t.match(params.headers, { 'content-type': 'application/vnd.elasticsearch+x-ndjson; compatible-with=8' })
1288+
t.match(params.headers, { 'content-type': 'application/x-ndjson' })
12891289
// @ts-expect-error
12901290
const [action, payload] = params.body.split('\n')
12911291
t.same(JSON.parse(action), { index: { _index: 'test' } })
@@ -1345,7 +1345,7 @@ test('Flush interval', t => {
13451345
onRequest (params) {
13461346
t.equal(params.path, '/_bulk')
13471347
t.match(params.headers, {
1348-
'content-type': 'application/vnd.elasticsearch+x-ndjson; compatible-with=8',
1348+
'content-type': 'application/x-ndjson',
13491349
'x-elastic-client-meta': `esv=${clientVersionNoMeta},js=${nodeVersion},t=${transportVersion},hc=${nodeVersion},h=bp`
13501350
})
13511351
// @ts-expect-error

0 commit comments

Comments
 (0)