Skip to content

PR #660 breaks POST requests in app with Plack::Middleware::Static #683

Open
@dboehmer

Description

@dboehmer

I am working on a Plack app using Plack::Middleware::Static and a coderef for path. Since #660 all POST requests fail because Plack::App::File returns 405 for non GET/HEAD requests regardless of the return value of the path coderef.

I think, the check for the HTTP method should be done only after path returned a true value. At the same time maybe we should another part of Plack to do the URL handling?

Our app has static files and dynamic endpoints mixed in the same namespace. Unfortunately the URL namespace was designed with a different scheme. I chose to use Plack::Middleware::Static to do the URL handling and handle static files.

The code looks like this:

builder {
    enable 'Plack::Middleware::Static', (
        path => sub {
            # manipulate path to match local files
            s/foo/bar/;

            if ( m/some paths must not be used as local files/ ) {
                return;
            }

            return 1; # serve local file or return 404
        },
        root => File::Spec->catdir( $PROJECT_ROOT, 'html' ),
    );

    # handlers for dynamic reqests ...
}

This is not the nicest thing but this is part of a longer migration from CGI to a modern web framework.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions