[going OT] Re: How To Dynamic Web Rendering?

Adam D. Ruppe destructionator at gmail.com
Thu May 12 14:45:27 PDT 2011


> Ugh. Apperently, too much Flash/PHP/HTML/etc has rotted my mind...

Speaking of brain rot, the first version of my cgi.d actually aimed
to mimic PHP! Some stupid part of me actually started to *like* the
superglobals for a while...

It had a static module constructor that built the arrays, and gave
them global names like PHP does:

import cgi;

void main() {
     auto my_var = _POST["my_var"]; // works in D
}

It even simulated PHP's session_start() thing, though bugs in
std.variant kept it from being particularly useful at the time.
While std.variant is now fixed, I haven't had a need for sessions
like that, so never updated that to the new module.



For some reason, I actually liked it at the time. But, it broke
down when I decided to write my own little http server to avoid
Apache bloat for an app. A shared, mutable global is obviously
nasty there.

(I did stick with it for a while, but it got so complicated I
ditched the whole stupid thing and started over, writing the
new class based cgi.d. If you look at my code though, you'll see
a couple things that are very bizarre according to the CGI standard:
these are the things that let it work with the embedded httpd too.
It reads all headers itself and writes the raw protocol to sockets
instead of stdout when constructed that way. Thus, aside from the
constructor arguments, the rest of the client code looks the same,
so I can switch from embedded to apache/iis and back easily enough.
The functions being mixin GenericMain!() instead of main() is also
due to this, though the try/catch it provides is nice too.)


Anywho.

Another bad experience with PHP led me to make the get and post
vars in cgi.d completely immutable - something that leads to
some pain, since phobos and druntime don't care much for
immutable(char[])'s (instead opting to work with
immutable(char)[]'s. This has gotten worse in the new beta with
even the replace() function no longer working on the former! Ugh!)

But, some minor hacks here and there make it work, so yay.

And, unlike PHP, if some asshole decides to write $_POST["evil"] =
$whatever; in his vile function, I won't have to deal with it later!
Whoo hoo!


More information about the Digitalmars-d-learn mailing list