Skip to content

Fix exception in predefined HTTP handler on absent header - #108324

Merged
vitlibar merged 1 commit into
ClickHouse:masterfrom
vitlibar:fix-http-handler-header-regex-missing-header
Jun 24, 2026
Merged

vitlibar merged 1 commit into
ClickHouse:masterfrom
vitlibar:fix-http-handler-header-regex-missing-header

Conversation

@vitlibar

@vitlibar vitlibar commented Jun 23, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix exception in predefined HTTP handler on absent header

The problem was found in PR #107492, it's that when a regular expression for a HTTP header allows empty string:

<clickhouse>
    <http_handlers>
        <rule>
            <methods>GET</methods>
            <url>/test_predefined_handler_absent_header</url>
            <headers_regexp><XXX><![CDATA[(?P<value_from_header>.*)]]></XXX></headers_regexp>
            <handler>
                <type>predefined_query_handler</type>
                <query>SELECT {value_from_header:String}</query>
            </handler>
        </rule>
    </http_handlers>
</clickhouse>

then it matches if a request doesn't have this header at all, but before this PR then it threw an exception trying to extract the value of a named capturing group from this header.

@clickhouse-gh

clickhouse-gh Bot commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b6224e2]

Summary: ✅


AI Review

Summary

This PR aligns PredefinedQueryHandler parameter extraction with headersFilter by treating an absent matched header as an empty string, avoiding the exception after a rule with an empty-string-matching header regex has already selected the handler. I found no unresolved correctness, safety, or metadata issues in the current diff; the focused integration test covers present, absent, and empty header values.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 23, 2026
assert response.content == b"hello\n"

# Header absent: the rule still matches and the captured parameter is empty.
response = get({})

@vitlibar vitlibar Jun 23, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it threw an exception before this PR's changes

@azat azat self-assigned this Jun 23, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.40% 85.40% +0.00%
Functions 92.60% 92.60% +0.00%
Branches 77.60% 77.60% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 3/3 (100.00%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@vitlibar
vitlibar added this pull request to the merge queue Jun 24, 2026
Merged via the queue into ClickHouse:master with commit 834059f Jun 24, 2026
328 of 330 checks passed
@vitlibar
vitlibar deleted the fix-http-handler-header-regex-missing-header branch June 24, 2026 14:55
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 24, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…eader-regex-missing-header

Fix exception in predefined HTTP handler on absent header
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants