Support rewriting status codes in error page middleware

This commit is contained in:
Daniel Peinhopf 2025-03-03 11:54:04 +01:00 committed by GitHub
parent f0849e8ee6
commit fa76ed57d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 195 additions and 8 deletions

View file

@ -69,6 +69,30 @@ func (s *ErrorPagesSuite) TestErrorPage() {
require.NoError(s.T(), err)
}
func (s *ErrorPagesSuite) TestStatusRewrites() {
// The `statusRewrites.toml` file contains a misconfigured backend host and some status code rewrites.
file := s.adaptFile("fixtures/error_pages/statusRewrites.toml", struct {
Server1 string
Server2 string
}{s.BackendIP, s.ErrorPageIP})
s.traefikCmd(withConfigFile(file))
frontendReq, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8080", nil)
require.NoError(s.T(), err)
frontendReq.Host = "test502.local"
err = try.Request(frontendReq, 2*time.Second, try.BodyContains("An error occurred."), try.StatusCodeIs(404))
require.NoError(s.T(), err)
frontendReq, err = http.NewRequest(http.MethodGet, "http://127.0.0.1:8080", nil)
require.NoError(s.T(), err)
frontendReq.Host = "test418.local"
err = try.Request(frontendReq, 2*time.Second, try.BodyContains("An error occurred."), try.StatusCodeIs(400))
require.NoError(s.T(), err)
}
func (s *ErrorPagesSuite) TestErrorPageFlush() {
srv := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
rw.Header().Add("Transfer-Encoding", "chunked")