1 package LJ
::Request
::Apache2
;
5 use Apache2
::Const qw
/:methods :common :http/;
6 use Apache2
::RequestUtil
;
7 use Apache2
::RequestRec
;
9 use Apache2
::RequestIO
;
11 use Apache2
::SubRequest
;
13 use Apache2
::ServerUtil
;
16 use Apache2
::Connection
;
23 sub LJ
::Request
::OK
{ return Apache2
::Const
::OK
}
24 sub LJ
::Request
::DONE
{ return Apache2
::Const
::DONE
}
25 sub LJ
::Request
::REDIRECT
{ return Apache2
::Const
::REDIRECT
}
26 sub LJ
::Request
::DECLINED
{ return Apache2
::Const
::DECLINED
}
27 sub LJ
::Request
::FORBIDDEN
{ return Apache2
::Const
::FORBIDDEN
}
28 sub LJ
::Request
::NOT_FOUND
{ return Apache2
::Const
::NOT_FOUND
}
29 sub LJ
::Request
::HTTP_NOT_MODIFIED
{ return Apache2
::Const
::HTTP_NOT_MODIFIED
}
30 sub LJ
::Request
::HTTP_MOVED_PERMANENTLY
{ return Apache2
::Const
::HTTP_MOVED_PERMANENTLY
}
31 sub LJ
::Request
::HTTP_MOVED_TEMPORARILY
{ return Apache2
::Const
::HTTP_MOVED_TEMPORARILY
}
32 sub LJ
::Request
::HTTP_METHOD_NOT_ALLOWED
{ return Apache2
::Const
::HTTP_METHOD_NOT_ALLOWED
() }
33 sub LJ
::Request
::HTTP_BAD_REQUEST
{ return Apache2
::Const
::HTTP_BAD_REQUEST
() }
34 sub LJ
::Request
::M_TRACE
{ return Apache2
::Const
::M_TRACE
}
35 sub LJ
::Request
::M_OPTIONS
{ return Apache2
::Const
::M_OPTIONS
}
36 sub LJ
::Request
::M_PUT
{ return Apache2
::Const
::M_PUT
}
37 sub LJ
::Request
::M_POST
{ return Apache2
::Const
::M_POST
() }
38 sub LJ
::Request
::SERVER_ERROR
{ return Apache2
::Const
::SERVER_ERROR
}
39 sub LJ
::Request
::BAD_REQUEST
{ return Apache2
::Const
::HTTP_BAD_REQUEST
}
40 sub LJ
::Request
::HTTP_GONE
{ return Apache2
::Const
::HTTP_GONE
}
41 sub LJ
::Request
::AUTH_REQUIRED
{ return Apache2
::Const
::AUTH_REQUIRED
}
42 sub LJ
::Request
::HTTP_PRECONDITION_FAILED
{ return Apache2
::Const
::HTTP_PRECONDITION_FAILED
}
46 sub LJ
::Request
::_get_instance
{
49 return $class if ref $class;
51 Carp
::confess
("Request is not provided to LJ::Request") unless $instance;
55 sub LJ
::Request
::interface_name
{ 'Apache2' }
57 sub LJ
::Request
::request
{ $instance }
60 return shift->_get_instance()->{r
};
63 sub LJ
::Request
::apr
{
64 return shift->_get_instance()->{apr
};
67 sub LJ
::Request
::_new
{
73 apr
=> Apache2
::Request
->new($r),
77 sub LJ
::Request
::instance
{
79 Carp
::confess
("use 'request' instead");
82 sub LJ
::Request
::init
{
86 # second init within a same request.
87 # Request object may differ between handlers.
88 if ($class->is_inited){
89 # NOTE. this is not good approach. becouse we would have Apache::Request based on other $r object.
94 $instance = LJ
::Request
->_new($r);
99 sub LJ
::Request
::prev
{
101 my $prev_handle = $class->r()->prev(@_);
102 return unless $prev_handle;
103 return LJ
::Request
->_new($prev_handle);
106 sub LJ
::Request
::is_inited
{
107 return $instance ?
1 : 0;
110 sub LJ
::Request
::update_mtime
{
112 return $class->r()->update_mtime(@_);
115 sub LJ
::Request
::set_last_modified
{
117 return $class->r()->set_last_modified(@_);
120 sub LJ
::Request
::request_time
{
122 return $class->r()->request_time();
125 sub LJ
::Request
::read {
127 return $class->r()->read(@_);
130 sub LJ
::Request
::is_main
{
132 return !$class->r()->main;
135 sub LJ
::Request
::main
{
137 return $class->r()->main(@_);
140 sub LJ
::Request
::dir_config
{
142 return $class->r()->dir_config(@_);
145 sub LJ
::Request
::header_only
{
147 return $class->r()->header_only;
150 sub LJ
::Request
::content_languages
{
152 return $class->r()->content_languages(@_);
155 sub LJ
::Request
::register_cleanup
{
157 return $class->r()->pool->cleanup_register(@_);
160 sub LJ
::Request
::path_info
{
162 return $class->r()->path_info(@_);
165 # $r->args in 2.0 returns the query string without parsing and splitting it into an array.
166 sub LJ
::Request
::args
{
170 my $qs = $r->args(@_);
172 map { URI
::Escape
::uri_unescape
($_) }
173 map { s/\+/ /g; $_ } # in query_string 'break' is encoded as '+' simbol
174 map { split /=/ => $_, 2 }
175 split /[\&\;]/ => $qs;
182 sub LJ
::Request
::method
{
187 sub LJ
::Request
::bytes_sent
{
189 $class->r()->bytes_sent(@_);
192 sub LJ
::Request
::document_root
{
194 $class->r()->document_root;
197 sub LJ
::Request
::finfo
{
199 $class->apr()->finfo;
202 sub LJ
::Request
::filename
{
204 $class->r()->filename(@_);
207 sub LJ
::Request
::add_httpd_conf
{
210 Apache2
::ServerUtil
->server->add_config(\
@confs);
213 sub LJ
::Request
::is_initial_req
{
215 $class->r()->is_initial_req(@_);
218 sub LJ
::Request
::push_handlers_global
{
222 $el =~ s/PerlHandler/PerlResponseHandler/g;
225 Apache2
::ServerUtil
->server->push_handlers(@handlers);
228 sub LJ
::Request
::push_handlers
{
232 $el =~ s/PerlHandler/PerlResponseHandler/g;
235 return $class->r()->push_handlers(@handlers);
238 sub LJ
::Request
::set_handlers
{
242 $el =~ s/PerlHandler/PerlResponseHandler/g;
245 $class->r()->set_handlers(@handlers);
248 sub LJ
::Request
::handler
{
250 $class->r()->handler(@_);
253 sub LJ
::Request
::method_number
{
255 return $class->r()->method_number(@_);
258 sub LJ
::Request
::status
{
260 return $class->r()->status(@_);
263 sub LJ
::Request
::status_line
{
265 return $class->r()->status_line(@_);
271 sub LJ
::Request
::free
{
277 sub LJ
::Request
::notes
{
279 return $class->r()->pnotes(@_);
282 sub LJ
::Request
::pnotes
{
284 $class->r()->pnotes (@_);
287 sub LJ
::Request
::parse
{
289 $class->r()->parse (@_);
292 sub LJ
::Request
::uri
{
294 $class->r()->uri (@_);
297 sub LJ
::Request
::hostname
{
299 $class->r()->hostname (@_);
302 sub LJ
::Request
::header_out
{
306 return $class->r()->err_headers_out->{$header} = shift;
308 return $class->r()->err_headers_out->{$header};
312 sub LJ
::Request
::headers_out
{
314 $class->r()->headers_out (@_);
317 sub LJ
::Request
::header_in
{
321 return $class->r()->headers_in->{$header} = shift;
323 return $class->r()->headers_in->{$header};
327 sub LJ
::Request
::headers_in
{
329 $class->r()->headers_in();
332 sub LJ
::Request
::param
{
334 $class->r()->param (@_);
337 sub LJ
::Request
::no_cache
{
339 $class->r()->no_cache (@_);
342 sub LJ
::Request
::content_type
{
344 $class->r()->content_type (@_);
347 sub LJ
::Request
::pool
{
352 sub LJ
::Request
::connection
{
354 $class->r()->connection;
357 sub LJ
::Request
::output_filters
{
359 $class->r()->output_filters(@_);
362 sub LJ
::Request
::print {
364 my $res = eval { $class->r()->print (@_) };
366 return undef if $@
=~ m
'Software caused connection abort'; ## that's not a real error.
367 ## upcoming client closed connection.
368 ## catch it and allow handler to complete work.
369 die $@
; ## throw error
374 sub LJ
::Request
::content_encoding
{
376 $class->r()->content_encoding(@_);
379 sub LJ
::Request
::send_http_header
{
381 # http://perl.apache.org/docs/2.0/user/porting/compat.html#C____r_E_gt_send_http_header___
382 # This method is not needed to be called in 2.0,
384 # http://perl.apache.org/docs/2.0/user/coding/coding.html#Forcing_HTTP_Response_Headers_Out
390 sub LJ
::Request
::err_headers_out
{
392 $class->r()->err_headers_out (@_)
395 sub LJ
::Request
::allowed
{
397 return $class->r()->allowed(@_);
401 ## Returns Array (Key, Value, Key, Value) which can be converted to HASH.
402 ## But there can be some params with the same name!
404 # TODO: do we need this and 'args' methods? they are much the same.
405 sub LJ
::Request
::get_params
{
409 my $qs = $r->args(@_);
410 my @args = split /[&;]/ => $qs;
413 s{\+} { }g; # in query_string 'break' is encoded as '+' simbol
414 URI
::Escape
::uri_unescape
($_)
417 defined $k?
($k, $v) : ();
424 sub LJ
::Request
::post_params
{
426 my $self = $class->_get_instance();
427 my $apr = $self->apr();
429 return @
{ $self->{params
} } if $self->{params
};
430 my (@params, %already_seen);
431 foreach my $name ($apr->body) {
432 next if $already_seen{$name}++;
433 foreach my $val ($apr->body($name)) {
434 push @params, ($name, $val);
437 $self->{params
} = \
@params;
441 sub LJ
::Request
::raw_content
{
443 my $self = $class->_get_instance();
444 my $r = $self->apr();
445 return $self->{raw_content
} if $self->{raw_content
};
446 $r->read($self->{raw_content
}, $r->headers_in()->get('Content-Length')) if $r->headers_in()->get('Content-Length');
447 return $self->{raw_content
};
450 sub LJ
::Request
::add_header_out
{
456 ## The difference between headers_out and err_headers_out, is that
457 ## the latter are printed even on error, and persist across internal redirects
458 ## (so the headers printed for ErrorDocument handlers will have them).
459 $r->err_headers_out->add($header, $value);
464 # TODO: maybe remove next method and use 'header_out' instead?
465 sub LJ
::Request
::set_header_out
{
471 ## The difference between headers_out and err_headers_out, is that
472 ## the latter are printed even on error, and persist across internal redirects
473 ## (so the headers printed for ErrorDocument handlers will have them).
474 $r->err_headers_out->set($header, $value);
479 sub LJ
::Request
::unset_headers_in
{
482 $class->r()->headers_in->unset($header);
485 sub LJ
::Request
::log_error
{
487 return $class->r()->log_error(@_);
490 sub LJ
::Request
::remote_ip
{
492 return $class->r()->connection()->remote_ip(@_);
495 sub LJ
::Request
::remote_host
{
497 return $class->r()->connection()->remote_host;
500 sub LJ
::Request
::user
{
502 return $class->r()->auth_name();
505 sub LJ
::Request
::aborted
{
507 return $class->r()->connection()->aborted;
510 sub LJ
::Request
::upload
{
512 return $class->apr()->upload(@_);
515 sub LJ
::Request
::sendfile
{
517 my $filename = shift;
518 my $fh = shift; # used in Apache v.1
520 return $class->r()->sendfile($filename);
523 sub LJ
::Request
::parsed_uri
{
525 $class->r()->parsed_uri; # Apache2::URI
528 sub LJ
::Request
::unparsed_uri
{
530 $class->r()->unparsed_uri; # Apache2::URI
533 sub LJ
::Request
::current_callback
{
535 return ModPerl
::Util
::current_callback
();
538 sub LJ
::Request
::child_terminate
{
540 return $class->r()->child_terminate;
543 sub LJ
::Request
::meets_conditions
{
545 return $class->r()->meets_conditions;