Skip to content

Commit

Permalink
Item13164: add support for gzip compression
Browse files Browse the repository at this point in the history
... of http response
  • Loading branch information
MichaelDaum committed Dec 17, 2014
1 parent bc66c87 commit d8b1829
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
3 changes: 2 additions & 1 deletion JsonRpcContrib/data/System/JsonRpcContrib.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" comment="reprev" date="1304090140" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" comment="reprev" date="1418801119" format="1.1" version="1"}%
---+!! %TOPIC%
%SHORTDESCRIPTION%

Expand Down Expand Up @@ -224,6 +224,7 @@ If a namespace, method, or parameters are specified as part of a JSON-RPC reques
| Release: | %$RELEASE% |
| Version: | %$VERSION% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 17 Dec 2014: | added support for gzip compression of http response |
| 28 Aug 2014: | don't use DEBUG constant to toggle local debug messages as it conflicts with Assert.pm |
| 11 Dec 2013: | removed dependency on JSON::XS |
| 30 May 2013: | added support for serialising objects, and rewrote some of the documentation (Foswiki:Main/CrawfordCurrie) |
Expand Down
6 changes: 3 additions & 3 deletions JsonRpcContrib/lib/Foswiki/Contrib/JsonRpcContrib.pm
Expand Up @@ -17,7 +17,7 @@ package Foswiki::Contrib::JsonRpcContrib;

use strict;
use warnings;
use Foswiki::Request;
use Foswiki::Request ();

BEGIN {
# Backwards compatibility for Foswiki 1.1.x
Expand All @@ -34,8 +34,8 @@ BEGIN {
=cut

our $VERSION = '2.12';
our $RELEASE = '2.12';
our $VERSION = '2.20';
our $RELEASE = '2.20';
our $SHORTDESCRIPTION = 'JSON-RPC interface for Foswiki';
our $NO_PREFS_IN_TOPIC = 1;
our $SERVER;
Expand Down
26 changes: 20 additions & 6 deletions JsonRpcContrib/lib/Foswiki/Contrib/JsonRpcContrib/Response.pm
Expand Up @@ -43,14 +43,28 @@ sub print {
my $class = shift;
my $session = shift;

my $this = $class->new( $session, @_ );
my $this = $class->new( $session, @_ );
my $response = $this->{session}->{response};
my $text = $this->encode();
my $hopts = {
'status' => $this->code() ? 500 : 200,
'Content-Type' => 'text/plain',
};

my $encoding = $ENV{'HTTP_ACCEPT_ENCODING'} || 'gzip';
$encoding =~ s/^.*(x-gzip|gzip).*/$1/g;

if ( $Foswiki::cfg{HttpCompress} || $ENV{'SPDY'} ) {
$hopts->{'Content-Encoding'} = $encoding;
$hopts->{'Vary'} = 'Accept-Encoding';

require Compress::Zlib;
$text = Compress::Zlib::memGzip($text);
}

$this->{session}->{response}->header(
-status => $this->code() ? 500 : 200,
-type => 'text/plain',
);
$response->setDefaultHeaders($hopts);

$this->{session}->{response}->print( $this->encode() );
$response->print($text);
}

##############################################################################
Expand Down

0 comments on commit d8b1829

Please sign in to comment.