Add api compatibility header support (#1478)

This commit is contained in:
Tomas Della Vedova
2021-07-13 09:47:45 +02:00
committed by delvedor
parent 187c229ba7
commit 5a6f5573e8
4 changed files with 75 additions and 4 deletions

View File

@ -1422,6 +1422,56 @@ test('Disable prototype poisoning protection', t => {
})
})
test('API compatibility header (json)', t => {
t.plan(4)
function handler (req, res) {
t.equal(req.headers.accept, 'application/vnd.elasticsearch+json; compatible-with=7')
t.equal(req.headers['content-type'], 'application/vnd.elasticsearch+json; compatible-with=7')
res.setHeader('Content-Type', 'application/vnd.elasticsearch+json; compatible-with=7')
res.end(JSON.stringify({ hello: 'world' }))
}
buildServer(handler, ({ port }, server) => {
process.env.ELASTIC_CLIENT_APIVERSIONING = 'true'
const client = new Client({
node: `http://localhost:${port}`
})
client.index({ index: 'foo', body: {} }, (err, { body }) => {
t.error(err)
t.same(body, { hello: 'world' })
server.stop()
delete process.env.ELASTIC_CLIENT_APIVERSIONING
})
})
})
test('API compatibility header (x-ndjson)', t => {
t.plan(4)
function handler (req, res) {
t.equal(req.headers.accept, 'application/vnd.elasticsearch+json; compatible-with=7')
t.equal(req.headers['content-type'], 'application/vnd.elasticsearch+x-ndjson; compatible-with=7')
res.setHeader('Content-Type', 'application/vnd.elasticsearch+json; compatible-with=7')
res.end(JSON.stringify({ hello: 'world' }))
}
buildServer(handler, ({ port }, server) => {
process.env.ELASTIC_CLIENT_APIVERSIONING = 'true'
const client = new Client({
node: `http://localhost:${port}`
})
client.bulk({ index: 'foo', body: [{}, {}] }, (err, { body }) => {
t.error(err)
t.same(body, { hello: 'world' })
server.stop()
delete process.env.ELASTIC_CLIENT_APIVERSIONING
})
})
})
test('Bearer auth', t => {
t.plan(3)