D2 & Web-Framework

Adam D. Ruppe destructionator at gmail.com
Thu Jul 14 15:22:38 PDT 2011


Nick Sabalausky wrote:
>  I'm having trouble figuring out how to use the executable.

You'll need to make sure the program is set to run as CGI
and that the stuff after the path is forwarded to the program.

In Apache, dropping it in cgi-bin does both for you, or you can do
a SetHandler cgi-script in any other location.

In IIS, you go to handler mappings on your web site and add the
program to the cgi handler. You might have to change cgi and api
restrictions too to allow it. (IIS seems to dislike CGI but if you
go through enough steps it can finally work. I don't use it often
though so I don't know all the edge cases and whatnot.)

If it works better with Fast CGI, I don't know if it does or not,
you might be able to compile cgi.d with -version=fastcgi and get
better results.

> FWIW, if I run it at the command-line, no matter what I give as
> the argument (or no argument) it just gives back:

CGI programs get info sent to them through the environment
variables and stdin. (I've been meaning to add a command line
alternatives but haven't gotten around to it yet.)

The function to call in web.d is determined by the PATH_INFO
envvar.

If it's blank, it asks the browser to redirect with the trailing
slash - that's the response you're seeing there.

(the reason it asks for this is so relative links to functions
work better.)


Try setting the environment variable PATH_INFO=/  and then running
the program. You should see your document spat out.


Calling other functions is then done by adding more path to the
url, which is again communicated through PATH_INFO.

url: mysite.com/myscript/myfunction

web server passes
PATH_INFO=/myfunction

program runs "myfunction();"


> that call
> "cgi.setResponseLocation()" with two arguments

I must have updated the public web.d but not the public cgi.d...

That second argument is fairly new. It means if the redirect is
important or not. The default is true.

If it's false, the redirect won't overwrite any existing redirect.


cgi.setResponseLocation("/mypage", true); // redirect is now mypage

cgi.setResponseLocation("/other", true); // overwrites - now redirect to other

cgi.setResponseLocation("/suggestion", false); // does not overwrite - this
redirect is not important



The not important one is useful if you want to redirect if and
only if there was no other redirect already set up.

Web.d uses it at the end of the user defined function as a default
behavior. If your function already specified a redirect, it won't
overwrite it.

Grab a new copy of the module:

http://arsdnet.net/dcode/cgi.d

And you can see the newer parameter with some slight documentation.


More information about the Digitalmars-d mailing list