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

Set some headers to hopefully be more in line with what bahn.de expects

parent 2d8088d8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ Module::Build->new(
		'List::Util'                 => 0,
		'LWP::UserAgent'             => 0,
		'LWP::Protocol::https'       => 0,
		'UUID'                       => 0,
	},
	script_files => 'bin/',
	sign         => 1,
+13 −1
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ use DateTime::Format::Strptime;
use Encode qw(decode encode);
use JSON;
use LWP::UserAgent;
use UUID qw(uuid4);

use Travel::Status::DE::DBRIS::Formation;
use Travel::Status::DE::DBRIS::JourneyAtStop;
@@ -42,6 +43,13 @@ sub new {
		results        => [],
		station        => $conf{station},
		ua             => $ua,
		header         => {
			'accept'           => 'application/json',
			'content-type'     => 'application/json; charset=utf-8',
			'Origin'           => 'https://www.bahn.de',
			'Referer'          => 'https://www.bahn.de/buchung/fahrplan/suche',
			'x-correlation-id' => uuid4() . '_' . uuid4(),
		},
	};

	bless( $self, $obj );
@@ -137,6 +145,10 @@ sub new {
			say "requesting $req";
		}

		while ( my ( $key, $value ) = each %{ $self->{header} } ) {
			$ua->default_header( $key => $value );
		}

		my ( $content, $error ) = $self->get_with_cache($req);

		if ($error) {
@@ -317,7 +329,7 @@ sub get_with_cache_p {
		say '  cache miss';
	}

	$self->{ua}->get_p($url)->then(
	$self->{ua}->get_p( $url => $self->{header} )->then(
		sub {
			my ($tx) = @_;
			if ( my $err = $tx->error ) {