|
14 | 14 | import com.clickhouse.client.api.enums.ProxyType; |
15 | 15 | import com.clickhouse.client.api.http.ClickHouseHttpProto; |
16 | 16 | import com.clickhouse.client.api.transport.Endpoint; |
| 17 | +import com.clickhouse.data.ClickHouseFormat; |
17 | 18 | import net.jpountz.lz4.LZ4Factory; |
18 | 19 | import org.apache.hc.client5.http.ConnectTimeoutException; |
19 | 20 | import org.apache.hc.client5.http.classic.methods.HttpPost; |
|
64 | 65 | import java.io.IOException; |
65 | 66 | import java.io.InputStream; |
66 | 67 | import java.io.OutputStream; |
| 68 | +import java.io.UnsupportedEncodingException; |
67 | 69 | import java.lang.reflect.Method; |
68 | 70 | import java.net.ConnectException; |
69 | 71 | import java.net.InetSocketAddress; |
@@ -449,13 +451,13 @@ private void addHeaders(HttpPost req, Map<String, Object> requestConfig) { |
449 | 451 | addHeader( |
450 | 452 | req, |
451 | 453 | ClickHouseHttpProto.HEADER_FORMAT, |
452 | | - requestConfig.get(ClientConfigProperties.INPUT_OUTPUT_FORMAT.getKey())); |
| 454 | + ((ClickHouseFormat) requestConfig.get(ClientConfigProperties.INPUT_OUTPUT_FORMAT.getKey())).name()); |
453 | 455 | } |
454 | 456 | if (requestConfig.containsKey(ClientConfigProperties.QUERY_ID.getKey())) { |
455 | 457 | addHeader( |
456 | 458 | req, |
457 | 459 | ClickHouseHttpProto.HEADER_QUERY_ID, |
458 | | - requestConfig.get(ClientConfigProperties.QUERY_ID.getKey())); |
| 460 | + (String) requestConfig.get(ClientConfigProperties.QUERY_ID.getKey())); |
459 | 461 | } |
460 | 462 | addHeader( |
461 | 463 | req, |
@@ -757,21 +759,25 @@ public void close() { |
757 | 759 | } |
758 | 760 |
|
759 | 761 | private static <T> void addHeader(HttpRequest req, String headerName, |
760 | | - T value) |
| 762 | + String value) |
761 | 763 | { |
762 | 764 | if (value == null) { |
763 | 765 | return; |
764 | 766 | } |
765 | | - String tString = value.toString(); |
766 | | - if (tString.isBlank()) { |
| 767 | + |
| 768 | + if (value.trim().isEmpty()) { |
767 | 769 | return; |
768 | 770 | } |
769 | | - if (PATTERN_HEADER_VALUE_ASCII.matcher(tString).matches()) { |
770 | | - req.addHeader(headerName, tString); |
| 771 | + if (PATTERN_HEADER_VALUE_ASCII.matcher(value).matches()) { |
| 772 | + req.addHeader(headerName, value); |
771 | 773 | } else { |
772 | | - req.addHeader( |
773 | | - headerName + "*", |
774 | | - "UTF-8''" + URLEncoder.encode(tString, StandardCharsets.UTF_8)); |
| 774 | + try { |
| 775 | + req.addHeader( |
| 776 | + headerName + "*", |
| 777 | + "UTF-8''" + URLEncoder.encode(value, StandardCharsets.UTF_8.name())); |
| 778 | + } catch (UnsupportedEncodingException e) { |
| 779 | + throw new ClientException("Failed to convert string to UTF8" , e); |
| 780 | + } |
775 | 781 | } |
776 | 782 | } |
777 | 783 |
|
|
0 commit comments