OT Adam D Ruppe's web stuff

Adam D. Ruppe destructionator at gmail.com
Thu Feb 9 06:56:02 PST 2012

On Thursday, 9 February 2012 at 08:26:25 UTC, Jacob Carlborg 
> For example, ENV["REQUEST_URI"] returns differently on 
> different servers. Rails provides a method, "request_uri" on 
> the request object that will return the same value on all 
> different servers.
> I don't know if CGI already has support for something similar.

Yeah, in cgi.d, you use Cgi.requestUri, which is an immutable
string, instead of using the environment variable directly.

   requestUri = getenv("REQUEST_URI");
// Because IIS doesn't pass requestUri, we simulate it here if 
it's empty.
    if(requestUri.length == 0) {
         // IIS sometimes includes the script name as part of the 
path info - we don't want that
         if(pathInfo.length >= scriptName.length && (pathInfo[0 .. 
scriptName.length] == scriptName))
             pathInfo = pathInfo[scriptName.length .. $];

            requestUri = scriptName ~ pathInfo ~ 
(queryString.length ? ("?" ~ queryString) : "");

           // FIXME: this works for apache and iis... but what 
about others?

That's in the cgi constructor. Somewhat ugly code, but I figure
better to have ugly code in the library than incompatibilities
in the user program!

The http constructor creates these variables from the raw headers.

Here's the ddoc:

If you search for "requestHeaders", you'll see all the stuff
following. If you use those class members instead of direct
environment variables, you'll get max compatibility.

More information about the Digitalmars-d mailing list