Skip to content

Conversation

@dunglas
Copy link
Collaborator

@dunglas dunglas commented Nov 3, 2025

Replaces php/frankenphp#1959.
May also be useful for Framer.

This allows setting the Server header during build using go build -ldflags '-X github.com/caddyserver/caddy.ServerHeader=FooBar'

This PR also micro-optimizes this code path.

Assistance Disclosure

No AI was used.

Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

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

Alright, nice improvement! Thank you!

@mholt mholt merged commit 8285eba into caddyserver:master Nov 4, 2025
23 checks passed
@mholt
Copy link
Member

mholt commented Nov 4, 2025

(To be clear, the Server header can already be set using Caddy config -- but this PR makes it possible to customize its static value which is optimized for the hot path.)

@dunglas dunglas deleted the feat/ServerHeader branch November 4, 2025 07:16
@mohammed90
Copy link
Member

Can we make it a const to avoid a plugin/module manipulating it at runtime?

@dunglas
Copy link
Collaborator Author

dunglas commented Nov 4, 2025

I don't think so (and it's convenient for FrankenPHP btw 😅)

@francislavoie
Copy link
Member

With an exported var technically there's a data race

@dunglas
Copy link
Collaborator Author

dunglas commented Nov 4, 2025

It's possible to make the variable unexported, but it will be less convenient for FrankenPHP (and maybe Framer btw).

@mohammed90
Copy link
Member

The build flag still works ever on const though. How is a const inconvenient?

@dunglas
Copy link
Collaborator Author

dunglas commented Nov 4, 2025

@francislavoie This is debatable. It should only called in an init() function and will be race free.

@mohammed90 so in FrankenPHP we can just change this variable instead of customizing our (plenty) build systems.

@mholt
Copy link
Member

mholt commented Nov 4, 2025

Why's there a data race by being exported?

@francislavoie
Copy link
Member

Cause if someone writes a stupid plugin that runs during HTTP requests that tries to change the variable, it can cause race.

@mholt
Copy link
Member

mholt commented Nov 4, 2025

Oh. I see... yes, that's true (as with any exported package var, I guess)

rob pike don't do that

@github-actions github-actions bot mentioned this pull request Dec 3, 2025
4 tasks
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.

4 participants