Subject: | Problem with compression in server mode |
Hi,
when I try to enabled compression on server call in SOAP::Lite I get errors.
I tried call to soap server via cURL:
curl -v -k --header "Content-Type: text/xml;charset=UTF-8" -H 'Accept-Encoding: gzip,deflate' --data @test.xml ip_address
It return: 'Content-Encoding => deflate' and some coded data. But when I add argument --compress to curl for automatically uncompressing files it show error.
So problem is in response call which try to run Encode::encode agains on compressed files which return miss broken data.
I attach simply patch "compression.patch" which remove this broken behaviour.
In attached file test_compression.pl is how it proceed in actual code and why it is broken.
Subject: | compression.patch |
--- SOAP-Lite-1.20/lib/SOAP/Transport/HTTP.pm~ 2017-08-12 21:41:13.000000000 +0200
+++ SOAP-Lite-1.20/lib/SOAP/Transport/HTTP.pm 2017-08-12 21:42:06.000000000 +0200
@@ -507,7 +507,7 @@
&& $encoding ? 'charset=' . lc($encoding) : () ),
'Content-Length' => SOAP::Utils::bytelength $response
),
- ( $] > 5.007 )
+ ( !$compressed && $] > 5.007 )
? do { require Encode; Encode::encode( $encoding, $response ) }
: $response,
) );
Subject: | test_compression.pl |
use Compress::Zlib;
require Encode;
require SOAP::Lite;
my $xml =<<EOL;
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:oair="https://qa.openair1.com:1443/OAirService">
<soapenv:Header>
<SessionHeader xsi:type="perl:SessionHeader" xmlns:perl="http://namespaces.soaplite.com/perl">
<sessionId xsi:type="xsd:string">xxxx</sessionId>
</SessionHeader>
</soapenv:Header>
<soapenv:Body>
<oair:add soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<objects xsi:type="perl:ArrayOfoaBase" xmlns:perl="http://namespaces.soaplite.com/perl"/>
</oair:add>
</soapenv:Body>
</soapenv:Envelope>
EOL
my $compress = Compress::Zlib::compress($xml);
my $encoded = Encode::encode( 'utf-8', $compress);
print "Compress: " . SOAP::Utils::bytelength($compress) . " Encoded:" . SOAP::Utils::bytelength($encoded);
print " Difference strings: " . ($compress cmp $encoded) . "\n";