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 |
|
&::syslog('info','', |
59 |
|
'document', |
60 |
|
$relPath, |
61 |
|
0, |
62 |
|
404 |
63 |
|
); |
64 |
|
|
65 |
return undef; |
return undef; |
66 |
} |
} |
67 |
|
|
68 |
$doc->serveTo($client); |
$doc->serveTo($client); |
69 |
|
|
70 |
|
$::Statistics->{'documents_served'}++; |
71 |
|
|
72 |
|
&::syslog('info','', |
73 |
|
'document', |
74 |
|
$relPath, |
75 |
|
$doc->{'size'}, |
76 |
|
200 |
77 |
|
); |
78 |
|
|
79 |
$doc; |
$doc; |
80 |
} |
} |
81 |
|
|
83 |
my $self=shift; |
my $self=shift; |
84 |
my $client=shift; |
my $client=shift; |
85 |
my $status=shift; |
my $status=shift; |
86 |
|
my $length=shift; |
87 |
|
my $contenttype=shift; |
88 |
|
$length = 0 unless ($length); |
89 |
|
$contenttype = "text/html" unless ($contenttype); |
90 |
|
|
91 |
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; |
|
92 |
|
|
93 |
$client->write($header); |
$client->write($header); |
94 |
} |
} |
248 |
sub serveTo { |
sub serveTo { |
249 |
my $self=shift; |
my $self=shift; |
250 |
my $client=shift; |
my $client=shift; |
251 |
|
my $ct = "text/html"; |
252 |
|
if ($self->{'path'} =~/\.(js)$/) { |
253 |
|
$ct = "text/javascript"; |
254 |
|
} |
255 |
|
|
256 |
$self->emitHeaderToClient($client,'200 OK'); |
$self->emitHeaderToClient($client,'200 OK',$self->{'size'}, $ct); |
257 |
|
|
258 |
$client->write($self->{'document'}); |
$client->write($self->{'document'}); |
259 |
|
|
260 |
} |
} |
261 |
|
|
262 |
sub path { |
sub path { |