You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the HttpConnection option with the ES client, and using the latest node.js v20 nightly, HTTP communication is broken.
nodejs/node#46904 recently (first in v20.0.0-nightly2023030448f99e5f6a nightly Node.js build) introduced a change to the internal isURL function that is used by http.request() and https.request() to decide if the first argument is a URL instance. The new test is if the object includes href and origin fields. If that is true, then Node's http.request() takes this code path which results in other fields like headers, agent, etc. being ignored.
HttpConnection.buildRequestObject hits this issue:
(I've opened issue nodejs/node#46981 on Node.js to discuss the change, but either way, I think this transport should change to only pass documented http.request() options.)
To Reproduce
// es-nodev20-break2.example.jsconstes=require('@elastic/elasticsearch')consthttp=require('http')// A mock ES server that responds with a valid response for a search request.constserver=http.createServer((req,res)=>{console.log('SERVER: on request: %s %s %s',req.method,req.url,req.headers)req.resume()req.on('end',()=>{res.writeHead(200,{'X-elastic-product': 'Elasticsearch','content-type': 'application/json'})constbody='{"took":0,"timed_out":false,"_shards":{"total":0,"successful":0,"skipped":0,"failed":0},"hits":{"total":{"value":0,"relation":"eq"},"max_score":0,"hits":[]}}'res.end(body)})})server.listen(0,'127.0.0.1',()=>{constserverUrl=`http://127.0.0.1:${server.address().port}`constclient=newes.Client({Connection: es.HttpConnection,node: serverUrl})client.search({q: 'pants'}).then(()=>{console.log('CLIENT: search success')}).finally(()=>{client.close()server.close()})})
Expected behavior
When run with the v20.0.0-nightly2023030448f99e5f6a node nightly, note that the custom headers from the ES client do not get through to the server:
https://nodejs.org/api/http.html#httprequestoptions-callback
Passing in the extra fields -- in particular 'href' and 'origin' --
makes node v20 believe the options object is a `URL` instance.
For a brief period, this broke with some node v20 nightlies.
Fixes: #59
🐛 Bug Report
When using the
HttpConnection
option with the ES client, and using the latest node.js v20 nightly, HTTP communication is broken.nodejs/node#46904 recently (first in v20.0.0-nightly2023030448f99e5f6a nightly Node.js build) introduced a change to the internal
isURL
function that is used byhttp.request()
andhttps.request()
to decide if the first argument is aURL
instance. The new test is if the object includeshref
andorigin
fields. If that is true, then Node'shttp.request()
takes this code path which results in other fields likeheaders
,agent
, etc. being ignored.HttpConnection.buildRequestObject
hits this issue:elastic-transport-js/src/connection/HttpConnection.ts
Lines 344 to 345 in 64d6fa2
(I've opened issue nodejs/node#46981 on Node.js to discuss the change, but either way, I think this transport should change to only pass documented
http.request()
options.)To Reproduce
Expected behavior
When run with the v20.0.0-nightly2023030448f99e5f6a node nightly, note that the custom headers from the ES client do not get through to the server:
But when run with earlier node.js versions, they do:
npm test
also fails with that node version.Your Environment
@elastic/elasticsearch
version: >=8.0.0The text was updated successfully, but these errors were encountered: