Permalink
Browse files

Wrap content_length check in an eval and fallback to other means if i…

…t fails. Should fix Apache2::RequestReq failure
  • Loading branch information...
claesjac committed Mar 13, 2012
1 parent 07bdcb9 commit 2c54217244f14bbfeed386739a74714fa9c56161
Showing with 16 additions and 4 deletions.
  1. +4 −2 Changes
  2. +1 −1 lib/JSON/RPC/Simple.pm
  3. +11 −1 lib/JSON/RPC/Simple/Dispatcher.pm
View
@@ -1,8 +1,10 @@
Revision history for Perl extension JSON::RPC::Simple.
-0.05 ...
+0.05 Tue Mar 13 2012
- Added a sample PSGI handler which loads service based on URI and dispatches them
-
+ - Wrap the content_length check in an eval and fallback to other methods of getting that
+ header if it fails (Apache2::RequestReq fix)
+
0.04 Wed Dec 7 2011
- Support for calls via HTTP GET
- t/03-client.t now doesn't fail because of faulty URL
View
@@ -6,7 +6,7 @@ use warnings;
use Scalar::Util qw(blessed refaddr);
use Carp qw(croak);
-our $VERSION = '0.04';
+our $VERSION = '0.05';
our $ClientClass = "JSON::RPC::Simple::Client";
sub connect {
@@ -140,7 +140,17 @@ sub handle {
return $self->_error($request, undef, 0, $self->errstr);
}
- unless (defined $request->content_length) {
+ # Some requests, like HTTP::Request lazy load content_length so we can't ->can("") it which is why the eval
+ my $content_length = eval { $request->content_length };
+ if ($@) {
+ # Apache2::RequestReq
+ $content_length = $request->headers_in->{'Content-Length'} if $request->can("headers_in");
+
+ # Fallback
+ $content_length = $request->headers->{'Content-Length'} if !defined $content_length && $request->can("headers");
+ };
+
+ unless (defined $content_length) {
$self->{errstr} =
"JSON-RPC 1.1 requires header Content-Length to be specified";
return $self->_error($request, undef, 0, $self->errstr);

0 comments on commit 2c54217

Please sign in to comment.