Skip to content

caddyhttp: add {http.request.proto_name} placeholder for spec-compliant protocol names - #7782

Merged
francislavoie merged 2 commits into
caddyserver:masterfrom
Jualhosting:fix-proto-name
Jun 4, 2026
Merged

francislavoie merged 2 commits into
caddyserver:masterfrom
Jualhosting:fix-proto-name

Conversation

@Jualhosting

@Jualhosting Jualhosting commented May 29, 2026 •

Copy link
Copy Markdown
Contributor

Before:
The {http.request.proto}\ placeholder returns the Go standard library's raw protocol representation (e.g., \HTTP/2.0\ or \HTTP/3.0). This diverges from standard web specifications which define these as \HTTP/2\ and \HTTP/3.

After:
This PR adds a new {http.request.proto_name}\ placeholder.
It utilizes a new helper function \GetProtoName(proto string)\ which maps raw Go protocol strings (\HTTP/2.0, \HTTP/3.0) to their spec-compliant names (\HTTP/2, \HTTP/3). Standard HTTP/1.x protocols remain unaffected.

Additionally, this PR updates the placeholder documentation in \�pp.go\ to clarify the distinction between {http.request.proto}\ (the raw Go string) and {http.request.proto_name}\ (the spec-defined name), and uses \httptest.NewRequest\ for proper error handling in the test cases.

Closes #7734

Assistance Disclosure
The root cause analysis, code modification, and documentation updates were performed with the assistance of Antigravity by Google Deepmind.

@steadytao steadytao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this should also update the placeholder table in modules/caddyhttp/app.go since the original issue was at least a documentation gap. Please document both placeholders there {http.request.proto} as Go’s raw http.Request.Proto value which may be HTTP/2.0 or HTTP/3.0 and {http.request.proto_name} as the spec-style protocol name.

Comment thread modules/caddyhttp/replacer_test.go Resolved
Comment thread modules/caddyhttp/replacer_test.go Resolved
@steadytao steadytao added the needs docs ✍️ Requires documentation changes label May 29, 2026
@steadytao

Copy link
Copy Markdown
Member

@francislavoie @chris-morgan Bumping this your way for your opinion.

@chris-morgan

chris-morgan commented May 30, 2026 •

Copy link
Copy Markdown

This sounds good to me. I presume docs changes would follow, wherever they go. (Oh, just saw the “needs docs” label.)

…nt protocol names

{http.request.proto} exposes Go's raw http.Request.Proto field which
returns HTTP/2.0 and HTTP/3.0 for HTTP/2 and HTTP/3 respectively.
These strings are non-standard since the specs define them as HTTP/2
and HTTP/3.

To preserve backward compat (especially CGI/FastCGI expectations),
{http.request.proto} is kept as-is. A new {http.request.proto_name}
placeholder is introduced that normalises the version string to the
spec-defined form:
  HTTP/2.0 -> HTTP/2
  HTTP/3.0 -> HTTP/3
  all others returned unchanged

Closes caddyserver#7734
@Jualhosting

Copy link
Copy Markdown
Contributor Author

@steadytao I have updated the PR to address your feedback. I added documentation for both placeholders in app.go and fixed the test cases in replacer_test.go (using httptest.NewRequest and removing the HTTP/4.0 case). Please let me know if there's anything else needed!

@steadytao steadytao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.

The app.go update should cover the generated HTTP app placeholder docs via moduledoc so I do not think a separate website PR is needed for the placeholder table itself unless we want additional explanatory prose elsewhere.

@steadytao steadytao added do not merge ⛔ Not ready yet! and removed needs docs ✍️ Requires documentation changes labels May 30, 2026
@steadytao
steadytao requested a review from francislavoie May 30, 2026 06:56
@steadytao

Copy link
Copy Markdown
Member

Just want a review from Francis as he was involved directly as well then I am happy to merge.

Also, @chris-morgan, docs are updated dynamically using moduledoc (albeit when Matt remembers to do so) via source comments and module metadata. So this PR would update the placeholder table and I can't see anywhere else that likely needs the additional prose from a quick scan through.

Comment thread modules/caddyhttp/replacer.go Resolved
@Jualhosting

Copy link
Copy Markdown
Contributor Author

I've updated the PR based on the feedback.

  • Switched to using
    eq.ProtoMajor\ for more robust {http.request.proto_name}\ normalization.
  • Updated the placeholder table in \modules/caddyhttp/app.go.
  • Refined the tests to use \httptest.NewRequest\ and verify the \ProtoMajor\ logic.

Tested locally and everything looks good!

@francislavoie francislavoie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks!

@francislavoie francislavoie added this to the v2.11.5 milestone Jun 4, 2026
@francislavoie
francislavoie merged commit 915793f into caddyserver:master Jun 4, 2026
29 checks passed
@steadytao steadytao removed the do not merge ⛔ Not ready yet! label Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

http.request.proto is wonky for HTTP/2 and HTTP/3 (there’s no such thing as “HTTP/2.0” or “HTTP/3.0”)

5 participants