ClickHouse / clickhouse-js

Official JS client for ClickHouse DB
https://clickhouse.com
Apache License 2.0
205 stars 25 forks source link

feat: added additional headers to clickhouse requests #224

Closed teawithfruit closed 7 months ago

teawithfruit commented 7 months ago

Summary

This PR enables clickhouse-js to use additional headers in http(s) requests. On my side it was necessary to be able to use a reverse proxy with basic auth in front. For example, something like this is possible from now on.

createClient({
  host: 'https://log.example.com',
  username: 'basic_auth_user',
  password: 'basic_auth_password',
  additionalHeaders: {
    'X-ClickHouse-User': 'clickhouse_user',
    'X-ClickHouse-Key': 'clickhouse_password',
  },
});

Checklist

Delete items not relevant to your PR:

CLAassistant commented 7 months ago

CLA assistant check
All committers have signed the CLA.

slvrtrn commented 7 months ago

@teawithfruit, thanks for the contribution. I took the liberty to do some fixups in the tests, plus I noticed that Record<string, number | string | string[]> was a bit too permissive (fetch API is a bit more strict on that), so I reduced it to Record<string, string> as it matches both APIs.

Released as 0.2.9.

teawithfruit commented 7 months ago

Thanks for reacting such fast. 🙂