MT#3925 Make API work with LWP::UserAgent.

First, properly "use" the Deflate module to import the Encoder stuff.
Second, disable Transport Encoding middleware entirely, as with "chunked"
responses sent by the API an LWP::UserAgent client is unable to properly
decode the response, resulting in broken binary answers.
agranig/rest
Andreas Granig 12 years ago
parent feebde1048
commit b5fca434e8

@ -30,7 +30,7 @@ require CHI::Driver::FastMmap;
use Log::Log4perl::Catalyst qw();
use NGCP::Panel::Cache::Serializer qw();
use NGCP::Panel::Middleware::HSTS qw();
use NGCP::Panel::Middleware::TEgzip qw();
#use NGCP::Panel::Middleware::TEgzip qw();
extends 'Catalyst';
our $VERSION = '0.01';
@ -157,7 +157,7 @@ __PACKAGE__->config(
}
},
'Plugin::EnableMiddleware' => [
NGCP::Panel::Middleware::TEgzip->new,
#NGCP::Panel::Middleware::TEgzip->new,
NGCP::Panel::Middleware::HSTS->new,
],
);

@ -1,7 +1,7 @@
package NGCP::Panel::Middleware::TEgzip;
use Sipwise::Base;
use HTTP::Headers::Util qw(split_header_words);
use Plack::Middleware::Deflater qw();
use Plack::Middleware::Deflater;
# for internal package Plack::Middleware::Deflater::Encoder
use Plack::Util qw();
extends 'Plack::Middleware';

@ -0,0 +1,22 @@
#!/usr/bin/perl -w
use strict;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new();
$ua->ssl_opts(
SSL_cert_file => '/etc/ssl/ngcp/api/NGCP-API-client-certificate-1385650532.pem',
SSL_key_file => '/etc/ssl/ngcp/api/NGCP-API-client-certificate-1385650532.pem',
SSL_ca_file => '/etc/ssl/ngcp/api/ca-cert.pem',
my $can_accept = HTTP::Message::decodable;
my $res = $ua->get(
'https://serenity:4443/api/contacts/?id=10',
#'Accept-Encoding' => $can_accept,
'Accept' => 'application/hal+json',
);
if($res->is_success) {
print $res->as_string;
} else {
print STDERR $res->status_line, "\n";
}
# vim: set tabstop=4 expandtab:
Loading…
Cancel
Save