Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.clickhouse.client.api.http;

import com.google.common.collect.ImmutableSet;

import java.util.Set;

public class ClickHouseHttpProto {


Expand Down Expand Up @@ -52,6 +56,22 @@ public class ClickHouseHttpProto {

public static final String HEADER_SSL_CERT_AUTH = "x-clickhouse-ssl-certificate-auth";

/** Server error tag header */
public static final String HEADER_ERROR_TAG = "X-ClickHouse-Exception-Tag";

public static final Set<String> RESPONSE_HEADER_WHITELIST;

static {
RESPONSE_HEADER_WHITELIST = ImmutableSet.<String>builder()
.add(ClickHouseHttpProto.HEADER_QUERY_ID)
.add(ClickHouseHttpProto.HEADER_SRV_SUMMARY)
.add(ClickHouseHttpProto.HEADER_SRV_DISPLAY_NAME)
.add(ClickHouseHttpProto.HEADER_DATABASE)
.add(ClickHouseHttpProto.HEADER_DB_USER)
.add(ClickHouseHttpProto.HEADER_ERROR_TAG)
.build();
}

/**
* Query parameter to specify the query ID.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
import java.util.Objects;
import java.util.Optional;
import java.util.Properties;
import java.util.Arrays;

Check warning on line 98 in client-v2/src/main/java/com/clickhouse/client/api/internal/HttpAPIClientHelper.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused import 'java.util.Arrays'.

See more on https://sonarcloud.io/project/issues?id=ClickHouse_clickhouse-java&issues=AZ0nLs8I7Lq6732fPXnx&open=AZ0nLs8I7Lq6732fPXnx&pullRequest=2807
import java.util.HashMap;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue;
Expand Down Expand Up @@ -754,14 +754,6 @@
return getHeaderVal(header, defaultValue, Integer::parseInt);
}

private static final Set<String> RESPONSE_HEADER_WHITELIST = new HashSet<>(Arrays.asList(
ClickHouseHttpProto.HEADER_QUERY_ID,
ClickHouseHttpProto.HEADER_SRV_SUMMARY,
ClickHouseHttpProto.HEADER_SRV_DISPLAY_NAME,
ClickHouseHttpProto.HEADER_DATABASE,
ClickHouseHttpProto.HEADER_DB_USER
));

/**
* Collects whitelisted response headers from an HTTP response into a map.
*
Expand All @@ -770,7 +762,7 @@
*/
public static Map<String, String> collectResponseHeaders(ClassicHttpResponse response) {
Map<String, String> headers = new HashMap<>();
for (String name : RESPONSE_HEADER_WHITELIST) {
for (String name : ClickHouseHttpProto.RESPONSE_HEADER_WHITELIST) {
Header header = response.getFirstHeader(name);
if (header != null) {
headers.put(name, header.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,35 @@
}
}

@Test(groups = { "integration" })
public void testInvalidSqlAfterHeadersSent() throws Exception {
if (isCloud()) {
return; // mocked server
}

ClickHouseNode server = getServer(ClickHouseProtocol.HTTP);

Check warning on line 798 in client-v2/src/test/java/com/clickhouse/client/HttpTransportTests.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this use of "ClickHouseNode"; it is deprecated.

See more on https://sonarcloud.io/project/issues?id=ClickHouse_clickhouse-java&issues=AZ0nLs7A7Lq6732fPXnw&open=AZ0nLs7A7Lq6732fPXnw&pullRequest=2807
try (Client client = new Client.Builder().addEndpoint(Protocol.HTTP, "localhost", server.getPort(), false)
.setUsername("default")
.setPassword(ClickHouseServerForTest.getPassword())
.build()) {

// Force delayed server-side failure after the query starts producing progress/headers.
QuerySettings settings = new QuerySettings()
.serverSetting("send_progress_in_http_headers", "1")
.serverSetting("max_result_rows", "1000000")
.serverSetting("result_overflow_mode", "throw")
.serverSetting("max_block_size", "1");

try (QueryResponse ignored = client.query("SELECT number FROM system.numbers", settings).get()) {
Assert.fail("Expected exception");
} catch (ServerException e) {
Assert.assertEquals(e.getCode(), 396);
Assert.assertTrue(e.getMessage().contains("Limit for rows or bytes exceeded"),
"Unexpected error message: " + e.getMessage());
}
}
}


@Test(groups = { "integration" }, dataProvider = "testUserAgentHasCompleteProductName_dataProvider", dataProviderClass = HttpTransportTests.class)
public void testUserAgentHasCompleteProductName(String clientName, Pattern userAgentPattern) throws Exception {
Expand Down
Loading