| 1 | # | ||
| 2 | # | ||
| 3 | # Copyright (C) 2006-2010 Andrew Speer <andrew@webdyne.org>. All rights | ||
| 4 | # reserved. | ||
| 5 | # | ||
| 6 | # This file is part of WebDyne::Request::FastCGI | ||
| 7 | # | ||
| 8 | # WebDyne is free software; you can redistribute it and/or modify | ||
| 9 | # it under the terms of the GNU General Public License as published by | ||
| 10 | # the Free Software Foundation; either version 2 of the License, or | ||
| 11 | # (at your option) any later version. | ||
| 12 | # | ||
| 13 | # This program is distributed in the hope that it will be useful, | ||
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 16 | # GNU General Public License for more details. | ||
| 17 | # | ||
| 18 | # You should have received a copy of the GNU General Public License | ||
| 19 | # along with this program; if not, write to the Free Software | ||
| 20 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 21 | # | ||
| 22 | # | ||
| 23 | package WebDyne::Request::FastCGI::Static; | ||
| 24 | |||
| 25 | |||
| 26 | # Compiler Pragma | ||
| 27 | # | ||
| 28 | use strict qw(vars); | ||
| 29 | use vars qw($VERSION $AUTOLOAD @ISA); | ||
| 30 | |||
| 31 | |||
| 32 | # External modules | ||
| 33 | # | ||
| 34 | use HTTP::Status (qw(RC_INTERNAL_SERVER_ERROR RC_NOT_FOUND)); | ||
| 35 | use IO::File; | ||
| 36 | use WebDyne::Base; | ||
| 37 | |||
| 38 | |||
| 39 | # Inheritance | ||
| 40 | # | ||
| 41 | use WebDyne::Request::FastCGI; | ||
| 42 | @ISA=qw(WebDyne::Request::FastCGI); | ||
| 43 | |||
| 44 | |||
| 45 | # Version information | ||
| 46 | # | ||
| 47 | $VERSION='1.002'; | ||
| 48 | |||
| 49 | |||
| 50 | # Debug load | ||
| 51 | # | ||
| 52 | 0 && debug("Loading %s version $VERSION", __PACKAGE__); | ||
| 53 | |||
| 54 | |||
| 55 | # All done. Positive return | ||
| 56 | # | ||
| 57 | 1; | ||
| 58 | |||
| 59 | |||
| 60 | #================================================================================================== | ||
| 61 | |||
| 62 | |||
| 63 | sub run { | ||
| 64 | |||
| 65 | my ($r, $self)=@_; | ||
| 66 | my $fn=$r->filename(); | ||
| 67 | if (!-f $fn) { | ||
| 68 | warn("file '$fn' not found"); | ||
| 69 | return $r->status(RC_NOT_FOUND); | ||
| 70 | } | ||
| 71 | elsif (my $fh=IO::File->new($fn, O_RDONLY)) { | ||
| 72 | my $hr=$r->headers_out(); | ||
| 73 | my $size=(stat($fn))[7]; | ||
| 74 | $hr->{'Content-Length'}=$size; | ||
| 75 | $r->send_http_header(); | ||
| 76 | while (<$fh>) { $r->print($_) } | ||
| 77 | $fh->close(); | ||
| 78 | return &Apache::OK | ||
| 79 | } | ||
| 80 | else { | ||
| 81 | warn("unable to open file '$fn', $!"); | ||
| 82 | return $r->status(RC_INTERNAL_SERVER_ERROR); | ||
| 83 | } | ||
| 84 | |||
| 85 | } |