Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client sent an HTTP request to an HTTPS server #2497

Open
ayelsew opened this issue Nov 22, 2024 · 1 comment
Open

Client sent an HTTP request to an HTTPS server #2497

ayelsew opened this issue Nov 22, 2024 · 1 comment

Comments

@ayelsew
Copy link

ayelsew commented Nov 22, 2024

🐛 Bug report

When I try to make a search request, server responds with "Client sent an HTTP request to an HTTPS server", even if I use a HTTPS URL

I put an console.log inside the transport layer of the library, and I saw this:

// /node_modules/.deno/@[email protected]/node_modules/@elastic/transport/lib/Transport.js:544:27
{
  body: "Client sent an HTTP request to an HTTPS server.\n",
  statusCode: 400,
  headers: {},
  meta: {
    context: null,
    request: {
      params: {
        method: "POST",
        path: "/_search",
        body: '{"_source":false,"query":{"term":{"_id":"xpto"}}}',
        querystring: "",
        headers: {
          "user-agent": "elasticsearch-js/8.15.2 (linux 6.11.9-zen1-1-zen-x64; Node.js 20.11.1; Transport 8.9.1)",
          "x-elastic-client-meta": "es=8.15.2,js=20.11.1,t=8.9.1,hc=20.11.1",
          authorization: "ApiKey omited",
          "content-type": "application/vnd.elasticsearch+json; compatible-with=8",
          accept: "application/vnd.elasticsearch+json; compatible-with=8",
          "content-length": "49"
        }
      },
      options: {},
      id: 1
    },
    name: "elasticsearch-js",
    connection: {
      url: "https://XPTO.aws.found.io/",
      id: "https://XPTO.aws.found.io/",
      headers: {
        "user-agent": "elasticsearch-js/8.15.2 (linux 6.11.9-zen1-1-zen-x64; Node.js 20.11.1; Transport 8.9.1)",
        "x-elastic-client-meta": "es=8.15.2,js=20.11.1,t=8.9.1,hc=20.11.1"
      },
      status: "alive"
    },
    attempts: 0,
    aborted: false
  },
  warnings: [Getter]
}

It are using the https:// schema, so think "I did the right thing"

Also I tested the last version 8.16.2, and had the same behavior

FYI: I had performed the same request using cURL or Postman, and it worked.

I tried to use the cloud ID too but it throw me the follow error:

const client = new Client({
    cloud: { id: "xpto" }
    auth: {
      apiKey: "XPTO"
    }
});
error: Uncaught (in promise) TypeError: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined
    at _from (ext:deno_node/internal/buffer.mjs:217:9)
    at Function.from (ext:deno_node/internal/buffer.mjs:229:10)
    at new Client (file:///home/ayelsew/Desktop/workers/node_modules/.deno/@[email protected]/node_modules/@elastic/elasticsearch/lib/client.js:91:38)
    at file:///home/ayelsew/Desktop/workers/src/infra/elastic/elastic_client.ts:3:16

But bout the cloud ID, I guess it is a Deno's limitation not elastic client.

To reproduce

setup client:

import { Client } from "@elastic/elasticsearch";

const client = new Client({
    node: "https://XPTO.aws.found.io:443",
    auth: {
      apiKey: "XPTO"
    }
});

Do a request search

client.search({
  _source: false,
  query: {
    term: { _id: 'xpto' },
  },
});

Expected behavior

I expect that search() method returns the result instead of throwing error "Client sent an HTTP request to an HTTPS server"

Node.js version

20.11.1

@elastic/elasticsearch version

8.15.2

Operating system

Garuda linux 6.11.9-zen1-1-zen-x64

Any other relevant environment information

deno 2.1.1 Elastic search version v8.15.2

@JoshMock
Copy link
Member

JoshMock commented Dec 2, 2024

Presumably you're using the default Connection, which is UndiciConnection. Can you verify whether it's that or HttpConnection?

My initial suspicion is that this could be a Deno issue. Since this client does not officially support Deno, I can't guarantee that I'll be able to solve your problem unless we can reproduce it on Node.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants