Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider allowing a PSGI arrayref as a run mode return value #7

Open
markstos opened this issue Feb 7, 2013 · 2 comments
Open

Consider allowing a PSGI arrayref as a run mode return value #7

markstos opened this issue Feb 7, 2013 · 2 comments

Comments

@markstos
Copy link
Owner

markstos commented Feb 7, 2013

Currently there are are two documented value return values for a run mode, a scalar and scalarref.

I think we should consider adding a third: If the return value is an arrayref, it would be expected to be a complete PSGI response that's passed through directly (without adding a response code or headers as we usually would.

Use Case

CGI::Application::Plugin::Stream could be replaced with a native PSGI solution. To stream a file, you could end a run mode like this:

return Plack::App::File->new(file => '/my/private/file.csv');

Like the Stream plugin, this would handle detecting the MIME Type and setting a Content-Type and Last-Modified headers, and converting it to a file handle. The server-side of the PSGI spec takes things from there.

I think if we don't add this, we'll end up needlessly rewriting solutions for cases like this, when we could be taking advantage of a native PSGI solution.

@anazawa
Copy link

anazawa commented Feb 8, 2013

How can you process the PSGI arrayref in CGI environment?
It seems that CGI::Application needs to do what Plack::Handler::CGI does.
I believe you are talking about PSGI::Application, not CGI::Application ;)

@markstos
Copy link
Owner Author

markstos commented Feb 8, 2013

@anazawa, I only intended the feature to work in CGI::Application. Implementing and documenting it in PSGI::Application would certainly be simpler, as there is only one code path. Still, I think it could of interest in CGI::Application: "When using run_as_psgi()", run modes have a third valid return value, which is to to return the PSGI arrayref directly, which includes in the HTTP response status code, HTTP headers and the full response. This is useful for example for streaming tools, that take care of generating all the headers as well as a callback for the body.

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

No branches or pull requests

2 participants