Unverified Commit fad1d59d authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Indicate that we accept brotli

At present, this fixes the 10-second delay for each request
parent bd8863bc
Loading
Loading
Loading
Loading
+2 −1
Changes for Build.PL: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -26,7 +26,8 @@ Module::Build->new(
		'DateTime::Duration'         => 0,
		'DateTime::Format::Strptime' => 0,
		'Getopt::Long'               => 0,
		'IO::Uncompress::Gunzip'              => 0,
		'HTTP::Request'              => '7.00',
		'IO::Uncompress::Brotli'     => '0.004_002',
		'JSON'                       => 0,
		'List::Util'                 => 0,
		'LWP::UserAgent'             => 0,
+4 −10
Changes for lib/Travel/Routing/DE/DBRIS.pm: 4 added lines, 10 removed lines.
Original line number Diff line number Diff line
@@ -15,7 +15,6 @@ use Encode qw(decode encode);
use JSON;
use LWP::UserAgent;
use UUID qw(uuid4);
use IO::Uncompress::Gunzip;
use Travel::Status::DE::DBRIS;
use Travel::Routing::DE::DBRIS::Connection;
use Travel::Routing::DE::DBRIS::Offer;
@@ -68,6 +67,7 @@ sub new {
		ua             => $ua,
		header         => {
			'accept'           => 'application/json',
			'accept-encoding'  => 'gzip, br',
			'content-type'     => 'application/json; charset=utf-8',
			'Origin'           => 'https://www.bahn.de',
			'Referer'          => 'https://www.bahn.de/buchung/fahrplan/suche',
@@ -231,19 +231,13 @@ sub new {
			$ua->default_header( $key => $value );
		}

		my ( $raw_content, $error )
		  = $self->post_with_cache( $req_url, $req_str );
		my ( $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 );
		}
@@ -322,7 +316,7 @@ sub post_with_cache {
	my $reply = $self->{ua}->post(
		$url,
		Accept            => 'application/json',
		'Accept-Encoding' => 'gzip',
		'Accept-Encoding' => 'gzip, br',
		'Accept-Language' => $self->{language},
		'Content-Type'    => 'application/json; charset=utf-8',
		Content           => $req,
@@ -331,7 +325,7 @@ sub post_with_cache {
	if ( $reply->is_error ) {
		return ( undef, $reply->status_line );
	}
	my $content = $reply->content;
	my $content = $reply->decoded_content;

	if ($cache) {
		$cache->freeze( "$url $req", \$content );