45 |
my $class=shift; |
my $class=shift; |
46 |
my $relPath=shift; |
my $relPath=shift; |
47 |
my $client=shift; |
my $client=shift; |
48 |
|
|
49 |
&::syslog('debug',"Meteor::Document: Request received for '%s'",$relPath); |
&::syslog('debug',"Meteor::Document: Request received for '%s'",$relPath); |
50 |
|
|
51 |
my $doc=$class->documentForPath($relPath); |
my $doc=$class->documentForPath($relPath); |
53 |
unless(defined($doc)) |
unless(defined($doc)) |
54 |
{ |
{ |
55 |
$class->emitHeaderToClient($client,'404 Not Found'); |
$class->emitHeaderToClient($client,'404 Not Found'); |
56 |
|
$::Statistics->{'documents_not_found'}++; |
57 |
|
|
58 |
return undef; |
return undef; |
59 |
} |
} |
60 |
|
|
61 |
$doc->serveTo($client); |
$doc->serveTo($client); |
62 |
|
|
63 |
|
$::Statistics->{'documents_served'}++; |
64 |
|
|
65 |
$doc; |
$doc; |
66 |
} |
} |
67 |
|
|
69 |
my $self=shift; |
my $self=shift; |
70 |
my $client=shift; |
my $client=shift; |
71 |
my $status=shift; |
my $status=shift; |
72 |
|
my $length=shift; |
73 |
|
my $contenttype=shift; |
74 |
|
$length = 0 unless ($length); |
75 |
|
$contenttype = "text/html" unless ($contenttype); |
76 |
|
|
77 |
my $header=$::CONF{'DocumentHeaderTemplate'}; |
my $header="HTTP/1.1 ".$status."\r\nServer: ".$::PGM."\r\nContent-Type: ".$contenttype."; charset=utf-8\r\nPragma: no-cache\r\nCache-Control: no-cache, no-store, must-revalidate\r\nExpires: Thu, 1 Jan 1970 00:00:00 GMT\r\nContent-length: ".$length."\r\n\r\n"; |
|
|
|
|
$header=~s/~([^~]+)~/ |
|
|
if(!defined($1) || $1 eq '') |
|
|
{ |
|
|
'~'; |
|
|
} |
|
|
elsif($1 eq 'server') |
|
|
{ |
|
|
$::PGM; |
|
|
} |
|
|
elsif($1 eq 'status') |
|
|
{ |
|
|
$status; |
|
|
} |
|
|
else |
|
|
{ |
|
|
''; |
|
|
} |
|
|
/gex; |
|
78 |
|
|
79 |
$client->write($header); |
$client->write($header); |
80 |
} |
} |
234 |
sub serveTo { |
sub serveTo { |
235 |
my $self=shift; |
my $self=shift; |
236 |
my $client=shift; |
my $client=shift; |
237 |
|
my $ct = "text/html"; |
238 |
|
if ($self->{'path'} =~/\.(js)$/) { |
239 |
|
$ct = "text/javascript"; |
240 |
|
} |
241 |
|
|
242 |
$self->emitHeaderToClient($client,'200 OK'); |
$self->emitHeaderToClient($client,'200 OK',$self->{'size'}, $ct); |
243 |
|
|
244 |
$client->write($self->{'document'}); |
$client->write($self->{'document'}); |
245 |
|
|
246 |
} |
} |
247 |
|
|
248 |
sub path { |
sub path { |