Making a CGI request to a program (fossil-scm) from Rack (Sinatra)

54 views
Skip to first unread message

Guillermo Estrada

unread,
Feb 19, 2012, 8:37:16 PM2/19/12
to Rack Development
Hi, I just hope this is the place where I'll find the answer.

Fossil-Scm is a Source Code Management System that has a built in web
server for tracking issues and a wiki and such. It supports CGI also
to avoid running long term processes while hosting multiple repos. The
documentation suggests creating a simple CGI script like this one for
each repo you would like to host:

#!/usr/bin/fossil
repository: /route/to/repo/name.fossil

And this is all fine and works wonders in my web hosting.

What I want to do is to create a Sinatra (Rack) app to manage those
repositories, user authentication, common operations, create, delete,
etc... But in order to do that, I want to be able to manipulate the
route and the output of those webpages called via CGI.

Is there a way to take a request from my Rack application, take some
parameters, send them to the program (fossil) as a CGI request (This I
don't know how) and then get the output html to analyze/modify/etc...
and then sending the response from my Rack app?

Any help would be GREATLY appreciated.

Joshua Ballanco

unread,
Feb 20, 2012, 11:24:45 AM2/20/12
to rack-...@googlegroups.com
You might start by reading the wiki page for CGI: http://en.wikipedia.org/wiki/Common_Gateway_Interface (and, if you're up to it, read RFC3875 after that). The moral of the story is that a CGI script is just a script that expects a variety of environment variables describing the request made, and the POST/PUT body on stdin. With a little bit of experimentation, I expect you should be able to simply shell-out to Fossil to do what you want.

Eric Wong

unread,
Feb 20, 2012, 2:29:25 PM2/20/12
to rack-...@googlegroups.com
Guillermo Estrada <phro...@gmail.com> wrote:
> Is there a way to take a request from my Rack application, take some
> parameters, send them to the program (fossil) as a CGI request (This I
> don't know how) and then get the output html to analyze/modify/etc...
> and then sending the response from my Rack app?

There's rack-legacy: git://github.com/eric1234/rack-legacy

unicorn still has a Unicorn::App::ExecCGI module I wrote
before rack-legacy existed:
http://bogomips.org/unicorn.git/tree/lib/unicorn/app/exec_cgi.rb
(The cgit instance on bogomips.org still runs off ExecCGI).

James Tucker

unread,
Feb 20, 2012, 4:08:53 PM2/20/12
to rack-...@googlegroups.com
rackup(1) that ships with rack can support cgi.


#!/usr/bin/env rackup
run Rack::Lobster

Guillermo Estrada

unread,
Feb 20, 2012, 7:41:13 PM2/20/12
to Rack Development
Rack-Legacy might be just EXACTLY what I was looking for :D Thanks for
the link. I just need to learn it and check if it's usable.

On Feb 20, 1:29 pm, Eric Wong <normalper...@yhbt.net> wrote:

Steve Klabnik

unread,
Feb 20, 2012, 8:18:45 AM2/20/12
to rack-...@googlegroups.com
Is Faraday what you want?
Reply all
Reply to author
Forward
0 new messages