Skip to content

http protocol filters - #23385

Closed
icing wants to merge 2 commits into
curl:masterfrom
icing:http-proto-filters
Closed

icing wants to merge 2 commits into
curl:masterfrom
icing:http-proto-filters

Conversation

@icing

@icing icing commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

protocol filters

new protocol callback setup_filters(struct Curl_easy *data, struct Curl_cfilter *cf) that allows a protocol handler to add filters into a connection filter chain.

The SETUP filter will call this once the TLS/Proxy/IP filters have connected. The protocol handler can then query the filter chain for properties like the negotiated ALPN and decide what to do. The SETUP filter will then connect any added filters before it becomes "connected" itself.

If a connection involves several SETUP filters (like with HTTPS-CONNECT), the protocol's setup_filters() will be called once by each SETUP filter.

http protocol filter

The HTTP protocol handler provides a setup_filters() callback to inspect the negotiated ALPN and adds a HTTP/2 filter when required.

This used to be checked in the HTTP protocol handler just before sending a request. This is no longer necessary. Also, the HTTPS-CONNECT filter no longer has to care about this.

A Cleaner Design

Before this change, a HTTP/2 connection was "established" without the HTTP/2 filter in place. It was deemed "completely connected", but it was incomplete, e.g. not really talking HTTP/2. An undefined state. When querying such a connection for properties like ALPN and HTTP version, the answers would not be consistent.

Other Use Cases

There are several protocol handlers in curl that have a "protoconnect" phase, e.g. where properties
with the server are negotiated and authentication may happen or TLS being added. It might be "better" to perform this an a protocol specific connection filter.

@icing icing added the feature-window A merge of this requires an open feature window label Oct 13, 2026
@icing
icing force-pushed the http-proto-filters branch from da4e813 to 3db2d7e Compare October 21, 2026 14:03
@icing icing added HTTP and removed feature-window A merge of this requires an open feature window labels Oct 21, 2026
@icing
icing requested a review from bagder October 21, 2026 14:38
@bagder
bagder requested a balanced review from Copilot October 22, 2026 06:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

HTTP/3-only validation is lost, and RTSP connections can incorrectly receive HTTP/2 filters.

2 open issues
What changed in this PR

This PR moves protocol-specific filter installation into connection setup, so HTTP/2 filters are connected before the connection is considered ready.

Changes:

  • Adds a protocol setup_filters callback and a corresponding SETUP phase.
  • Moves HTTP/2 filter selection from request handling and HTTPS-CONNECT into the HTTP callback.
  • Updates protocol registrations and adds filter-chain HTTP-version queries.
File Description
lib/​ws.c Registers HTTP filter setup for WebSocket connections.
lib/​vssh/​libssh2.c Adds null callbacks for SCP and SFTP.
lib/​vssh/​libssh.c Adds null callbacks for SCP and SFTP.
lib/​tftp.c Adds a null filter-setup callback.
lib/​telnet.c Adds a null filter-setup callback.
lib/​smtp.c Adds a null filter-setup callback.
lib/​rtsp.c Registers HTTP filter setup for RTSP.
lib/​protocol.h Defines the protocol filter-setup callback.
lib/​pop3.c Adds a null filter-setup callback.
lib/​openldap.c Updates the OpenLDAP protocol registration.
lib/​mqtt.c Updates MQTT and secure MQTT registrations.
lib/​ldap.c Updates the LDAP protocol registration.
lib/​imap.c Adds a null filter-setup callback.
lib/​http2.h Updates filter-local HTTP/2 switching declarations.
lib/​http2.c Makes HTTP/2 insertion operate at a specified filter.
lib/​http.h Declares the HTTP filter-setup callback.
lib/​http.c Moves HTTP version selection into filter setup.
lib/​gopher.c Updates Gopher protocol registrations.
lib/​ftp.c Adds a null filter-setup callback.
lib/​file.c Adds a null filter-setup callback.
lib/​dict.c Adds a null filter-setup callback.
lib/​cfilters.h Declares filter-chain HTTP-version queries.
lib/​cfilters.c Implements filter-chain HTTP-version queries.
lib/​cf-setup.c Adds and connects protocol filters during setup.
lib/​cf-https-connect.c Removes HTTP/2 insertion from HTTPS-CONNECT.

Review effort: Balanced

Comment thread lib/rtsp.c Resolved
Comment thread lib/http.c Resolved
icing added 2 commits October 22, 2026 10:01
Add a protocol callback `setup_filter()` that lets protocol
handlers install their own connection filters once the base
connection has been brought up.

cf-setup call this once the IP/TLS/PROXY filters have connected.

http protocol filters

Use the protocol handler's `setup_filters()` callback to check on
new HTTP connections ALPN and version needs to see if additional
filters like HTTP/2 need to be added.

Removes the need to check this in cf-https-connect.c as cf-setup
implicitly takes care of this now.
- RTSP: check and limit HTTP versions to negotiate
- HTTP: resurrect setup_connection() callback
@icing
icing force-pushed the http-proto-filters branch from 3db2d7e to b12ce33 Compare October 22, 2026 08:37
@bagder bagder closed this in f394995 Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

2 participants