I've taken the cookbook examples for the web server (the forking one is
rather cool) and am wondering if anyone has fully implementated a web server
and if so are they willing to release the code?

I've hacked together parts, I can tell if the user is requesting a .pl and
if so I eval it (this is totally internal so I'm not too concerned about
security yet), etc but I'm probably missing some stuff.

here is what I've added to the forked web server example:

    $response->content_type("text/html");

    # figure out what we're doing, if it's a .html or .htm the just read
    # the file in, if it's a .pl the process the file

    # note that we are relative to our current path..
    my $fname = $Root . $request->uri();
    my $type = substr( $fname, rindex( $fname, "." ) );

    # handle the problem of args in the filename
    my @work = split( /\?/, $fname, 2 );

    # if there was a ? then reformat the filename
    if( $#work > 0 ) {
      $fname = shift( @work );
      $type = substr( $fname, rindex( $fname, "." ) );

      $ENV{QUERY_STRING} = $work[0];
    }

    # reset the reply data -- this should probably be an error msg.
    $data = "";

    DEBUG and warn "Fname = '$fname' \n";

    # snarf up the file, add a simple cache next.
    if( -e $fname ) {
        local(*INPUT, $/);

        if( open (INPUT, $fname) ) {
          $data = <INPUT>;
        }
    } else {
      $type = "";
      $data = "File '$fname' not found";
    }

    # see if we need to parse the data, if so then we need to remap the
    # STDOUT to a local variable so we can capture the script data
    if( $type eq ".pl" ) {
      my $output;
      tie *STDOUT, 'IO::Scalar', \$output;

      eval $data ;

      # get a copy of what was done
      $data = $output;
    }

    # DEBUG and warn "type = '$type', Data = '$data'\n";

    $response->content( $data );

    $heap->{client}->put($response);

it's not the greatest but I'm wondering what everyone has done..

thx,
bobm

Reply via email to