diff --git a/conn_http.go b/conn_http.go index d3732f6a26..419691fe4c 100644 --- a/conn_http.go +++ b/conn_http.go @@ -161,9 +161,9 @@ func dialHttp(ctx context.Context, addr string, num int, opt *Options) (*httpCon u.User = url.User(opt.Auth.Username) } } else if opt.TLS != nil && len(opt.Auth.Username) > 0 { - headers["X-Clickhouse-User"] = opt.Auth.Username + headers["X-ClickHouse-User"] = opt.Auth.Username if len(opt.Auth.Password) > 0 { - headers["X-Clickhouse-Key"] = opt.Auth.Password + headers["X-ClickHouse-Key"] = opt.Auth.Password } } @@ -205,13 +205,13 @@ func dialHttp(ctx context.Context, addr string, num int, opt *Options) (*httpCon client: &http.Client{ Transport: t, }, - url: u, - buffer: new(chproto.Buffer), - compression: opt.Compression.Method, - blockCompressor: compress.NewWriter(), - compressionPool: compressionPool, - blockBufferSize: opt.BlockBufferSize, - additionalHttpHeaders: headers, + url: u, + buffer: new(chproto.Buffer), + compression: opt.Compression.Method, + blockCompressor: compress.NewWriter(), + compressionPool: compressionPool, + blockBufferSize: opt.BlockBufferSize, + headers: headers, } location, err := conn.readTimeZone(ctx) if err != nil { @@ -231,27 +231,27 @@ func dialHttp(ctx context.Context, addr string, num int, opt *Options) (*httpCon client: &http.Client{ Transport: t, }, - url: u, - buffer: new(chproto.Buffer), - compression: opt.Compression.Method, - blockCompressor: compress.NewWriter(), - compressionPool: compressionPool, - location: location, - blockBufferSize: opt.BlockBufferSize, - additionalHttpHeaders: headers, + url: u, + buffer: new(chproto.Buffer), + compression: opt.Compression.Method, + blockCompressor: compress.NewWriter(), + compressionPool: compressionPool, + location: location, + blockBufferSize: opt.BlockBufferSize, + headers: headers, }, nil } type httpConnect struct { - url *url.URL - client *http.Client - location *time.Location - buffer *chproto.Buffer - compression CompressionMethod - blockCompressor *compress.Writer - compressionPool Pool[HTTPReaderWriter] - blockBufferSize uint8 - additionalHttpHeaders map[string]string + url *url.URL + client *http.Client + location *time.Location + buffer *chproto.Buffer + compression CompressionMethod + blockCompressor *compress.Writer + compressionPool Pool[HTTPReaderWriter] + blockBufferSize uint8 + headers map[string]string } func (h *httpConnect) isBad() bool { diff --git a/conn_http_async_insert.go b/conn_http_async_insert.go index 55dd82d01e..361f220f47 100644 --- a/conn_http_async_insert.go +++ b/conn_http_async_insert.go @@ -32,7 +32,7 @@ func (h *httpConnect) asyncInsert(ctx context.Context, query string, wait bool) if wait { options.settings["wait_for_async_insert"] = 1 } - res, err := h.sendQuery(ctx, strings.NewReader(query), &options, nil) + res, err := h.sendQuery(ctx, strings.NewReader(query), &options, h.headers) if res != nil { defer res.Body.Close() // we don't care about result, so just discard it to reuse connection diff --git a/conn_http_batch.go b/conn_http_batch.go index dcc29a26f8..d9692a1c84 100644 --- a/conn_http_batch.go +++ b/conn_http_batch.go @@ -215,6 +215,9 @@ func (b *httpBatch) Send() (err error) { options.settings["query"] = b.query headers["Content-Type"] = "application/octet-stream" + for k, v := range b.conn.headers { + headers[k] = v + } res, err := b.conn.sendQuery(b.ctx, r, &options, headers) if res != nil { diff --git a/conn_http_exec.go b/conn_http_exec.go index ec6581626d..89afce8689 100644 --- a/conn_http_exec.go +++ b/conn_http_exec.go @@ -32,7 +32,7 @@ func (h *httpConnect) exec(ctx context.Context, query string, args ...interface{ options := queryOptions(ctx) - res, err := h.sendQuery(ctx, strings.NewReader(query), &options, nil) + res, err := h.sendQuery(ctx, strings.NewReader(query), &options, h.headers) if res != nil { defer res.Body.Close() // we don't care about result, so just discard it to reuse connection diff --git a/conn_http_query.go b/conn_http_query.go index fbff92ea2e..828fc58321 100644 --- a/conn_http_query.go +++ b/conn_http_query.go @@ -44,7 +44,7 @@ func (h *httpConnect) query(ctx context.Context, release func(*connect, error), headers["Accept-Encoding"] = h.compression.String() } - for k, v := range h.additionalHttpHeaders { + for k, v := range h.headers { headers[k] = v }