summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBirte Kristina Friesel <birte.friesel@uos.de>2025-02-20 17:49:28 +0100
committerBirte Kristina Friesel <birte.friesel@uos.de>2025-02-20 17:49:28 +0100
commita02f519eb4eff269d77cfacb86e149f6a5a9518b (patch)
tree9a42c7e3843c7bc676f71045ecf8a0262d906fef /lib
parent6141430b13ac39a606f8bfb8872aea490688abb0 (diff)
As of today, bahn.de sends gzip-compressed replies
Diffstat (limited to 'lib')
-rw-r--r--lib/Travel/Routing/DE/DBRIS.pm16
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/Travel/Routing/DE/DBRIS.pm b/lib/Travel/Routing/DE/DBRIS.pm
index bae8e1b..1d2e6b1 100644
--- a/lib/Travel/Routing/DE/DBRIS.pm
+++ b/lib/Travel/Routing/DE/DBRIS.pm
@@ -14,6 +14,7 @@ use DateTime::Format::Strptime;
use Encode qw(decode encode);
use JSON;
use LWP::UserAgent;
+use IO::Uncompress::Gunzip;
use Travel::Status::DE::DBRIS;
use Travel::Routing::DE::DBRIS::Connection;
use Travel::Routing::DE::DBRIS::Offer;
@@ -203,23 +204,23 @@ sub new {
say "requesting $req_str";
}
- my ( $content, $error ) = $self->post_with_cache( $req_url, $req_str );
+ my ( $raw_content, $error )
+ = $self->post_with_cache( $req_url, $req_str );
if ($error) {
$self->{errstr} = $error;
return $self;
}
+ my $gunzip = IO::Uncompress::Gunzip->new( \$raw_content, Append => 1 );
+ my $content = q{};
+
+ while ( $gunzip->read($content) ) { }
+
if ( $self->{developer_mode} ) {
say decode( 'utf-8', $content );
}
- # Sometimes, bahn.de adds garbage at the end
- if ( $content =~ m/^[^{]/ or $content =~ m/[^}]$/ ) {
- $content =~ s/^[^{]+//;
- $content =~ s/[^}]+$//;
- }
-
$self->{raw_json} = $json->decode($content);
if ( $conf{from} and $conf{to} ) {
$self->parse_connections;
@@ -294,6 +295,7 @@ sub post_with_cache {
my $reply = $self->{ua}->post(
$url,
Accept => 'application/json',
+ 'Accept-Encoding' => 'gzip',
'Accept-Language' => $self->{language},
'Content-Type' => 'application/json; charset=utf-8',
Content => $req,