How To Dynamic Web Rendering?

Nick Sabalausky a at a.a
Thu May 19 13:07:57 PDT 2011


"Matthew Ong" <ongbp at yahoo.com> wrote in message 
news:ir3anp$dgj$1 at digitalmars.com...
> On 5/13/2011 4:01 AM, Nick Sabalausky wrote:
>>
>> Here's a basic "Hello world" CGI app in D:
>>
>> // hellocgi.d
>> import std.conv;
>> import std.stdio;
>>
>> void main()
> Hmm...Might be problem for it to be main... Security concerned because of 
> the publicity done my M$ and others also. When they pushed for ASP/JSP...

What's wrong with it? This is the first I've heard of any such issue.

>> {
>>      // Read in HTTP request headers
>>      string[] requestHeaders;
>>      while(true)
>>      {
>>          string line = readln();
>>          if(line.length<= 1)
>>              break;
>>
>>          requestHeaders ~= line;
>>      }
>>
>>      // Send response headers
>>      writeln("Status: 200 OK");
>>      writeln("Content-Type: text/html; charset=UTF-8");
>>      writeln();
>>
>>      // Send content
>>      writeln("<b><i>Hello world</i></b>");
>> }
>>
>> Compile with:
>> dmd hellocgi.d
>>
>> And just stick the resulting "hellocgi.exe" (windows) or "hellocgi" 
>> (other)
>> in whatever "cgi-bin"-capable directory you have on your server.
> Thanks for this Example also. I will keep it for later trial.
>

Actually, like Adam pointed out, I got the HTTP request headers part 
completely wrong. HTTP headers come from environment variables, and stdin is 
just used for any data that's been posted. So that part's totally wrong. So 
you'll want to just rip that part out like this:

// hellocgi.d
import std.conv;
import std.stdio;

void main()

{
     // Send response headers
     writeln("Status: 200 OK");
     writeln("Content-Type: text/html; charset=UTF-8");
     writeln();

     // Send content
     writeln("<b><i>Hello world</i></b>");
}


>> I'm sure it's possible to make an ISAPI filter or Apache module in D, but
>> I've never really done that in any langauge, and I haven't really dealt 
>> with
>> DLLs much, so I wouldn't know how. But even as CGI, a web app in D is 
>> likely
>> to still be much faster than one in, for instance, PHP or Ruby.
> Why I am looking for DLL as compare to exe is becuase it is a well know 
> security concern
> published and accepted as minimum by the industry for MNC.
>

First I've heard of it. What's the problem?




More information about the Digitalmars-d-learn mailing list