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

Adding a CGI utility #960

Open
LevitatingBusinessMan opened this issue Dec 11, 2024 · 2 comments
Open

Adding a CGI utility #960

LevitatingBusinessMan opened this issue Dec 11, 2024 · 2 comments

Comments

@LevitatingBusinessMan
Copy link

Hey!

I personally sometimes use slim as a CGI utility. slimrb works fine for this but to set the headers I use a little ruby prefix like

ruby:
	require "cgi"
	puts CGI.new.http_header "text/html"

# rest of template

This is needed to adhere to the CGI specifications. Additionally this method cannot be used to correctly set the Content-Size.

So now I use a little helper utility command called slimcgi which looks like this:

#!/usr/bin/env ruby
require "cgi"
require "slim"
$cgi = CGI.new
$cgi.out("text/html") do
	Slim::Template.new { ARGF.read }.render
end

It exposes the CGI class to the template and correctly sets the headers.

Do you think a utility like this could be added to this repository?

@minad
Copy link
Member

minad commented Dec 24, 2024

We could add an option --cgi to slimrb if that would help?

@LevitatingBusinessMan
Copy link
Author

I think that would be a decent solution, with the downside that maybe not all webservers could support it. I can particularly think of lighttpd that does not allow to add arguments to CGI binaries. But as long as spawn-fcgi works, which is the most common usecase then I think it's fine.

I added such a flag here https://github.com/LevitatingBusinessMan/slim/tree/cgi and am currently trying to do some tests with it.

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