Skip to content

caddyhttp: Add status_code option to http_redirect listener wrapper - #8062

Open
hsdfat wants to merge 1 commit into
caddyserver:masterfrom
hsdfat:http-redirect-status-code
Open

hsdfat wants to merge 1 commit into
caddyserver:masterfrom
hsdfat:http-redirect-status-code

Conversation

@hsdfat

@hsdfat hsdfat commented Sep 25, 2026

Copy link
Copy Markdown

Closes #6499

The http_redirect listener wrapper always answered plaintext HTTP requests on the HTTPS port with a 308. This adds a status_code option so the redirect can be made non-permanent (e.g. 307) or use another redirect code.

  • JSON: "status_code": 307 (default remains 308); validated to be one of 301, 302, 303, 307, 308.
  • Caddyfile (the wrapper previously had no Caddyfile options):
{
	servers {
		listener_wrappers {
			http_redirect {
				status_code 307
			}
			tls
		}
	}
}

Tests: unit tests that send a plaintext request through the wrapped listener and check the written status line and Location for each code, validation and Caddyfile parsing tables, and a caddyfile_adapt test.

Assistance Disclosure

I used AI assistants (Claude, OpenAI models) while writing and reviewing this change; I verified the behaviour and tests myself.

The HTTP->HTTPS redirect written by the http_redirect listener wrapper
was always a 308. Allow configuring it to 301, 302, 303, 307 or 308,
defaulting to 308, and add Caddyfile support:

	http_redirect {
		status_code 307
	}

Closes caddyserver#6499
@CLAassistant

CLAassistant commented Sep 25, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@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.

Looks decent. CLA needs to be signed.

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_redirect module prefer 307 Temporary Redirect

3 participants