Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 2c54217244f14bbfeed386739a74714fa9c56161 1 parent 07bdcb9
@claesjac authored
View
6 Changes
@@ -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
2  lib/JSON/RPC/Simple.pm
@@ -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 {
View
12 lib/JSON/RPC/Simple/Dispatcher.pm
@@ -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);
Please sign in to comment.
Something went wrong with that request. Please try again.