@@ -492,6 +492,63 @@ defmodule Ch.QueryTest do
492492 assert :proplists . get_keys ( headers_continue ) == :proplists . get_keys ( headers_normal )
493493 end
494494
495+ test "mixed-case x-clickhouse-format overrides the default" , % {
496+ conn: conn ,
497+ query_options: query_options
498+ } do
499+ for header_name <- [
500+ "x-clickhouse-format" ,
501+ "X-ClickHouse-Format" ,
502+ "x-ClIcKhOuSe-FoRmAt"
503+ ] do
504+ assert % Ch.Result { data: "1\n " , headers: headers , names: nil , rows: nil } =
505+ Ch . query! (
506+ conn ,
507+ "SELECT 1" ,
508+ % { } ,
509+ Keyword . merge ( query_options , headers: [ { header_name , "CSV" } ] )
510+ )
511+
512+ assert :proplists . get_value ( "x-clickhouse-format" , headers ) == "CSV"
513+ end
514+ end
515+
516+ test "mixed-case user-agent overrides the default" , % {
517+ conn: conn ,
518+ query_options: query_options
519+ } do
520+ assert % Ch.Result { rows: [ [ "custom-agent/ABC" ] ] } =
521+ Ch . query! (
522+ conn ,
523+ "SELECT getClientHTTPHeader('user-agent')" ,
524+ % { } ,
525+ Keyword . merge ( query_options ,
526+ headers: [ { "User-Agent" , "custom-agent/ABC" } ] ,
527+ settings: [ allow_get_client_http_header: 1 ]
528+ )
529+ )
530+ end
531+
532+ test "first x-clickhouse-format header wins regardless of case" , % {
533+ conn: conn ,
534+ query_options: query_options
535+ } do
536+ assert % Ch.Result { data: "1\n " , headers: headers } =
537+ Ch . query! (
538+ conn ,
539+ "SELECT 1" ,
540+ % { } ,
541+ Keyword . merge ( query_options ,
542+ headers: [
543+ { "X-ClickHouse-Format" , "CSV" } ,
544+ { "x-clickhouse-format" , "JSONEachRow" }
545+ ]
546+ )
547+ )
548+
549+ assert :proplists . get_value ( "x-clickhouse-format" , headers ) == "CSV"
550+ end
551+
495552 test "connection works after failure in execute" , % { conn: conn , query_options: query_options } do
496553 assert { :error , % Ch.Error { } } = Ch . query ( conn , "wat" , [ ] , query_options )
497554 assert [ [ 42 ] ] = Ch . query! ( conn , "SELECT 42" , [ ] , query_options ) . rows
0 commit comments