Perl max_chunk_size additions
authorBill Erickson <berick@esilibrary.com>
Mon, 24 Feb 2014 20:14:19 +0000 (15:14 -0500)
committerMike Rylander <mrylander@gmail.com>
Fri, 12 Aug 2016 18:57:46 +0000 (14:57 -0400)
* Added missing max_chunk_size method to AppSession
* Copy API max_chunk_size value into the handler AppRequest
* Fix error where no-chunking resulted in empty responses

Signed-off-by: Bill Erickson <berick@esilibrary.com>
src/perl/lib/OpenSRF/AppSession.pm
src/perl/lib/OpenSRF/Application.pm

index 7454970..ba3aa54 100644 (file)
@@ -892,6 +892,13 @@ sub max_bundle_size {
        return $self->{max_bundle_size};
 }
 
+sub max_chunk_size {
+       my $self = shift;
+       my $value = shift;
+       $self->{max_chunk_size} = $value if (defined($value));
+       return $self->{max_chunk_size};
+}
+
 sub recv_timeout {
        my $self = shift;
        my $timeout = shift;
@@ -1034,27 +1041,31 @@ sub respond {
        my $msg = shift;
        return unless ($self and $self->session and !$self->complete);
 
-
     my $type = 'RESULT';
        my $response;
        if (ref($msg) && UNIVERSAL::isa($msg, 'OpenSRF::DomainObject::oilsResponse')) {
                $response = $msg;
         $type = 'STATUS' if UNIVERSAL::isa($response, 'OpenSRF::DomainObject::oilsStatus');
-       } elsif ($self->max_chunk_size > 0) { # we might need to chunk
-        my $str = OpenSRF::Utils::JSON->perl2JSON($msg);
-        if (length($str) > $self->max_chunk_size) { # send partials ("chunking")
-            for (my $i = 0; $i < length($str); $i += $self->max_chunk_size) {
-                $response = new OpenSRF::DomainObject::oilsResult::Partial;
-                       $response->content( substr($str, $i, $self->max_chunk_size) );
-                   $self->session->send($type, $response, $self->threadTrace);
+
+       } else {
+
+        if ($self->max_chunk_size > 0) { # we might need to chunk
+            my $str = OpenSRF::Utils::JSON->perl2JSON($msg);
+            if (length($str) > $self->max_chunk_size) { # send partials ("chunking")
+                for (my $i = 0; $i < length($str); $i += $self->max_chunk_size) {
+                    $response = new OpenSRF::DomainObject::oilsResult::Partial;
+                    $response->content( substr($str, $i, $self->max_chunk_size) );
+                    $self->session->send($type, $response, $self->threadTrace);
+                }
+                # This triggers reconstruction on the remote end
+                $response = new OpenSRF::DomainObject::oilsResult::PartialComplete;
+                return $self->session->send($type, $response, $self->threadTrace);
             }
-            # This triggers reconstruction on the remote end
-            $response = new OpenSRF::DomainObject::oilsResult::PartialComplete;
-               return $self->session->send($type, $response, $self->threadTrace);
-        } else {
-            $response = new OpenSRF::DomainObject::oilsResult;
-            $response->content( $msg );
         }
+
+        # message failed to exceed max chunk size OR chunking disabled
+        $response = new OpenSRF::DomainObject::oilsResult;
+        $response->content($msg);
     }
 
     if ($self->{max_bundle_count} > 0 or $self->{max_bundle_size} > 0) { # we are bundling, and we need to test the size or count
index 9749a1d..fedd902 100644 (file)
@@ -182,6 +182,7 @@ sub handler {
                        my $appreq = OpenSRF::AppRequest->new( $session );
                        $appreq->max_bundle_size( $coderef->max_bundle_size );
                        $appreq->max_bundle_count( $coderef->max_bundle_count );
+                       $appreq->max_chunk_size( $coderef->max_chunk_size );
 
                        $log->debug( "in_request = $in_request : [" . $appreq->threadTrace."]", INTERNAL );
                        if( $in_request ) {