Skip to content

Commit

Permalink
Wrap content_length check in an eval and fallback to other means if i…
Browse files Browse the repository at this point in the history
…t fails. Should fix Apache2::RequestReq failure
  • Loading branch information
claesjac committed Mar 13, 2012
1 parent 07bdcb9 commit 2c54217
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
6 changes: 4 additions & 2 deletions Changes
@@ -1,8 +1,10 @@
Revision history for Perl extension JSON::RPC::Simple. 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 - 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 0.04 Wed Dec 7 2011
- Support for calls via HTTP GET - Support for calls via HTTP GET
- t/03-client.t now doesn't fail because of faulty URL - t/03-client.t now doesn't fail because of faulty URL
Expand Down
2 changes: 1 addition & 1 deletion lib/JSON/RPC/Simple.pm
Expand Up @@ -6,7 +6,7 @@ use warnings;
use Scalar::Util qw(blessed refaddr); use Scalar::Util qw(blessed refaddr);
use Carp qw(croak); use Carp qw(croak);


our $VERSION = '0.04'; our $VERSION = '0.05';


our $ClientClass = "JSON::RPC::Simple::Client"; our $ClientClass = "JSON::RPC::Simple::Client";
sub connect { sub connect {
Expand Down
12 changes: 11 additions & 1 deletion lib/JSON/RPC/Simple/Dispatcher.pm
Expand Up @@ -140,7 +140,17 @@ sub handle {
return $self->_error($request, undef, 0, $self->errstr); 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} = $self->{errstr} =
"JSON-RPC 1.1 requires header Content-Length to be specified"; "JSON-RPC 1.1 requires header Content-Length to be specified";
return $self->_error($request, undef, 0, $self->errstr); return $self->_error($request, undef, 0, $self->errstr);
Expand Down

0 comments on commit 2c54217

Please sign in to comment.