Skip to content

BUG: Headers added on error pages are not sent to client #5739

@Benjamin-K

Description

@Benjamin-K

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

If you add headers in fusion or in a middleware to your error pages (Status Code = 404), those headers are not sent to the client.

In a middleware, all code after $next->handle($request); won't be executed.

Other changes (like adding an attribute to the html tag) work as expected.

Expected Behavior

Adding headers to error pages should work through fusion or a middleware.

Steps To Reproduce

  1. Add a new document/page on the first level of your site with uriPathSegment = 404 (or use existing error page).

  2. Add the following code to your Root.fusion file in your site package:

    // This part could be skipped, if you have an existing error page
    error {
        @context.notfoundDocument = ${q(site).children('[uriPathSegment=404]').get(0)}
    
        4xx {
            @position = 'start'
            condition = ${statusCode >= 400 && statusCode < 500 && notfoundDocument}
            renderer = Neos.Fusion:Renderer {
                @context.node = ${notfoundDocument}
                // type = ${q(notfoundDocument).property('_nodeType')}
                type = 'Vendor.Site:Document.NotFound'
                renderPath >
            }
        }
    }
    
    // IMPORTANT: Add httpResponseHead.headers with a custom header to your error page
    prototype(Vendor.Site:Document.NotFound) < prototype(Neos.Neos:Page) {
        httpResponseHead.headers {
            X-Custom-Header = 'My-Test-Value'
        }
    
        // Optional, just for demo
        body >
        body = 'This is my error page'
    }
    
  3. Open browser with an open developer console.

  4. Visit any unknown url that will trigger the error page to be rendered and view the returned http headers.

Environment

- Flow: 8.4.2
- Neos: 8.4.2
- PHP:  8.4

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions