@@ -37,8 +37,8 @@ func init() {
3737 commitHash = "unknown"
3838}
3939
40- func Connect (url , jwt , host string , schemaDb bool , encryptionKey string ) driver.Conn {
41- return & hranaV2Conn {url , jwt , host , schemaDb , encryptionKey , "" , false , 0 }
40+ func Connect (url , jwt , host string , schemaDb bool , encryptionKey string , requestHeaders map [ string ] string ) driver.Conn {
41+ return & hranaV2Conn {url , jwt , host , schemaDb , encryptionKey , requestHeaders , "" , false , 0 }
4242}
4343
4444type hranaV2Stmt struct {
@@ -88,6 +88,7 @@ type hranaV2Conn struct {
8888 host string
8989 schemaDb bool
9090 remoteEncryptionKey string
91+ requestHeaders map [string ]string
9192 baton string
9293 streamClosed bool
9394 replicationIndex uint64
@@ -123,11 +124,11 @@ func (h *hranaV2Conn) PrepareContext(ctx context.Context, query string) (driver.
123124
124125func (h * hranaV2Conn ) Close () error {
125126 if h .baton != "" {
126- go func (baton , url , jwt , host , encryptionKey string ) {
127+ go func (baton , url , jwt , host , encryptionKey string , requestHeaders map [ string ] string ) {
127128 msg := hrana.PipelineRequest {Baton : baton }
128129 msg .Add (hrana .CloseStream ())
129- _ , _ , _ = sendPipelineRequest (context .Background (), & msg , url , jwt , host , encryptionKey )
130- }(h .baton , h .url , h .jwt , h .host , h .remoteEncryptionKey )
130+ _ , _ , _ = sendPipelineRequest (context .Background (), & msg , url , jwt , host , encryptionKey , requestHeaders )
131+ }(h .baton , h .url , h .jwt , h .host , h .remoteEncryptionKey , h . requestHeaders )
131132 }
132133 return nil
133134}
@@ -175,7 +176,7 @@ func (h *hranaV2Conn) sendPipelineRequest(ctx context.Context, msg *hrana.Pipeli
175176 if h .replicationIndex > 0 {
176177 addReplicationIndex (msg , h .replicationIndex )
177178 }
178- result , streamClosed , err := sendPipelineRequest (ctx , msg , h .url , h .jwt , h .host , h .remoteEncryptionKey )
179+ result , streamClosed , err := sendPipelineRequest (ctx , msg , h .url , h .jwt , h .host , h .remoteEncryptionKey , h . requestHeaders )
179180 if streamClosed {
180181 h .streamClosed = true
181182 }
@@ -232,7 +233,7 @@ func getReplicationIndex(response *hrana.PipelineResponse) uint64 {
232233 return replicationIndex
233234}
234235
235- func sendPipelineRequest (ctx context.Context , msg * hrana.PipelineRequest , url string , jwt string , host string , remoteEncryptionKey string ) (result hrana.PipelineResponse , streamClosed bool , err error ) {
236+ func sendPipelineRequest (ctx context.Context , msg * hrana.PipelineRequest , url string , jwt string , host string , remoteEncryptionKey string , requestHeaders map [ string ] string ) (result hrana.PipelineResponse , streamClosed bool , err error ) {
236237 reqBody , err := json .Marshal (msg )
237238 if err != nil {
238239 return hrana.PipelineResponse {}, false , err
@@ -254,6 +255,9 @@ func sendPipelineRequest(ctx context.Context, msg *hrana.PipelineRequest, url st
254255 }
255256
256257 req .Host = host
258+ for name , value := range requestHeaders {
259+ req .Header .Set (name , value )
260+ }
257261 resp , err := http .DefaultClient .Do (req )
258262 if err != nil {
259263 return hrana.PipelineResponse {}, false , err
@@ -597,11 +601,11 @@ func (h *hranaV2Conn) QueryContext(ctx context.Context, query string, args []dri
597601
598602func (h * hranaV2Conn ) closeStream () {
599603 if h .baton != "" {
600- go func (baton , url , jwt , host , encryptionKey string ) {
604+ go func (baton , url , jwt , host , encryptionKey string , requestHeaders map [ string ] string ) {
601605 msg := hrana.PipelineRequest {Baton : baton }
602606 msg .Add (hrana .CloseStream ())
603- _ , _ , _ = sendPipelineRequest (context .Background (), & msg , url , jwt , host , encryptionKey )
604- }(h .baton , h .url , h .jwt , h .host , h .remoteEncryptionKey )
607+ _ , _ , _ = sendPipelineRequest (context .Background (), & msg , url , jwt , host , encryptionKey , requestHeaders )
608+ }(h .baton , h .url , h .jwt , h .host , h .remoteEncryptionKey , h . requestHeaders )
605609 h .baton = ""
606610 }
607611}
0 commit comments