Skip to content

HttpMethodValidator produces 404 instead of 405 response #24018

Open
@schmengler

Description

@schmengler

Summary

The validation based on the new (2.3.0+) HTTP method marker interfaces (HttpGetActionInterface, HttpPostActionInterface, ...) throw an exception that is turned into a 404 response by the front controller:

        throw new InvalidRequestException(
            new NotFoundException(new Phrase('Page not found.'))
        );

A proper response status code would be 405 Method Not Allowed.

Steps to reproduce

  1. Make a GET request to an action with HttpPostActionInterface
  2. Watch the status code received.

Expected Result

  1. 404 Not Found.

Actual Result

  1. 405 Method Not Allowed.

Proposed solution

  1. Use a different "replace result" than NotFoundException that at least returns an error page with the correct status code. Minimum solution: send correct status code
  2. Do not mis-use exceptions as results at all Architectural improvement: do not mix unrelated types
  3. Add more marker interfaces to determine the type of result, i.e. JsonActionInterface, HtmlActionInterface, ... and return a different body depending on those Ideal solution: enable handling of 405 errors in different context

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: HTTPIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is not validGate 1 Failed. Automatic verification of issue format is failedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentPriority: P3May be fixed according to the position in the backlog.Progress: ready for devReproduced on 2.3.xThe issue has been reproduced on latest 2.3 releaseSeverity: S3Affects non-critical data or functionality and does not force users to employ a workaround.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions