Added custom header tests - #3060
Conversation
Client V2 CoverageCoverage Report
Class Coverage
|
JDBC V2 CoverageCoverage Report
Class Coverage
|
JDBC V1 CoverageCoverage Report
Class Coverage
|
Client V1 CoverageCoverage Report
Class Coverage
|
TriageCategory: Summary What this impacts
Concerns
Required reviewer action
|
|
|
@cursor review |
There was a problem hiding this comment.
Pull request overview
This PR adds test coverage and documentation for passing custom HTTP headers (especially X-ClickHouse-Replica-Tag for ClickHouse Cloud sticky sessions) and standardizes WireMock usage across modules by centralizing its version in the parent POM.
Changes:
- Add WireMock-based unit tests validating that V1
custom_http_headersare applied to HTTP requests (JDBC v1 path and Apache HTTP client path). - Document how to configure custom HTTP headers for the Java client and JDBC (including ClickHouse Cloud sticky-session guidance).
- Introduce
HEADER_REPLICA_TAGconstants and centralize the WireMock version via${wiremock.version}.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| pom.xml | Adds ${wiremock.version} property for reuse across modules. |
| jdbc-v2/pom.xml | Switches WireMock dependency to use ${wiremock.version}. |
| client-v2/pom.xml | Switches WireMock dependency to use ${wiremock.version}. |
| clickhouse-http-client/pom.xml | Switches WireMock dependency to use ${wiremock.version}. |
| clickhouse-jdbc/pom.xml | Adds WireMock test dependency (using ${wiremock.version}) for new tests. |
| client-v2/src/main/java/com/clickhouse/client/api/http/ClickHouseHttpProto.java | Adds HEADER_REPLICA_TAG constant for reuse in docs/code. |
| clickhouse-http-client/src/main/java/com/clickhouse/client/http/config/ClickHouseHttpOption.java | Adds HEADER_REPLICA_TAG constant for V1 HTTP stack. |
| clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHouseConnectionTest.java | Adds WireMock unit test validating V1 custom headers. |
| clickhouse-http-client/src/test/java/com/clickhouse/client/http/ApacheHttpConnectionImplTest.java | Adds WireMock unit test validating V1 custom headers for Apache HTTP provider. |
| docs/clickhouse-docs/jdbc.mdx | Documents JDBC v2 custom header configuration and ClickHouse Cloud sticky sessions; clarifies v1 vs v2 behavior. |
| docs/clickhouse-docs/client.mdx | Documents client-v2 custom header APIs and ClickHouse Cloud sticky sessions; updates option key mapping. |
Suppressed comments (1)
docs/clickhouse-docs/client.mdx:373
- This example also uses
clientBuilderwithout defining it, making the snippet incomplete.
clientBuilder.setOption(ClientConfigProperties.httpHeader("X-ClickHouse-Quota"), "test");
// equivalent to:
clientBuilder.setOption("http_header_X-CLICKHOUSE-QUOTA", "test");
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| String otherReplicaTag = "other-" + replicaTag; | ||
| WireMockServer mockServer = new WireMockServer(WireMockConfiguration.options().dynamicPort()); | ||
| mockServer.start(); | ||
| try { | ||
| mockServer.addStubMapping(WireMock.post(WireMock.anyUrl()) | ||
| .withHeader(ClickHouseHttpOption.HEADER_REPLICA_TAG, WireMock.equalTo(replicaTag)) | ||
| .withHeader("Host", WireMock.equalTo(host)) | ||
| .withRequestBody(WireMock.matching("(?is)select\\s+hostname\\(\\).*")) | ||
| .willReturn(WireMock.ok("hostname()\nString\n" + expectedReplica + "\n")) | ||
| .build()); | ||
| mockServer.addStubMapping(WireMock.post(WireMock.anyUrl()) | ||
| .withHeader(ClickHouseHttpOption.HEADER_REPLICA_TAG, WireMock.equalTo(otherReplicaTag)) | ||
| .withHeader("Host", WireMock.equalTo(host)) | ||
| .withRequestBody(WireMock.matching("(?is)select\\s+hostname\\(\\).*")) | ||
| .willReturn(WireMock.ok("hostname()\nString\nother-replica\n")) | ||
| .build()); |
| /** | ||
| * Replica tag used by a proxy to route a request to a specific replica. | ||
| */ | ||
| public static final String HEADER_REPLICA_TAG = "X-ClickHouse-Replica-Tag"; | ||
|
|
| String otherReplicaTag = "other-" + replicaTag; | ||
| WireMockServer mockServer = new WireMockServer(WireMockConfiguration.options().dynamicPort()); | ||
| mockServer.start(); | ||
| try { | ||
| mockServer.addStubMapping(WireMock.post(WireMock.anyUrl()) | ||
| .withHeader(ClickHouseHttpOption.HEADER_REPLICA_TAG, WireMock.equalTo(replicaTag)) | ||
| .withHeader("Host", WireMock.equalTo(host)) | ||
| .withRequestBody(WireMock.matching("(?is)select\\s+hostname\\(\\).*")) | ||
| .willReturn(WireMock.ok("hostname()\nString\n" + expectedReplica + "\n")) | ||
| .build()); | ||
| mockServer.addStubMapping(WireMock.post(WireMock.anyUrl()) | ||
| .withHeader(ClickHouseHttpOption.HEADER_REPLICA_TAG, WireMock.equalTo(otherReplicaTag)) | ||
| .withHeader("Host", WireMock.equalTo(host)) | ||
| .withRequestBody(WireMock.matching("(?is)select\\s+hostname\\(\\).*")) | ||
| .willReturn(WireMock.ok("hostname()\nString\nother-replica\n")) | ||
| .build()); |
| **Multiple values for one header** | ||
|
|
||
| ```java showLineNumbers | ||
| clientBuilder.httpHeader("X-Forwarded-For", Arrays.asList("1.2.3.4", "5.6.7.8")); |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 8ae294d. Configure here.



Summary
X-ClickHouse-Replica-Tagheader constant toClientHttpOptionsandcom.clickhouse.client.api.http.ClickHouseHttpProtoChecklist
Delete items not relevant to your PR: