From e5dca31c89f64bfa137b9b6f0009cc6af0c186f2 Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Sun, 9 Feb 2025 14:21:18 +0100 Subject: HAFAS: post_with_cache_p: Use proxy if required and specified for service --- lib/Travel/Status/DE/HAFAS.pm | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/Travel/Status/DE/HAFAS.pm b/lib/Travel/Status/DE/HAFAS.pm index bc274d7..da2d1c2 100644 --- a/lib/Travel/Status/DE/HAFAS.pm +++ b/lib/Travel/Status/DE/HAFAS.pm @@ -472,7 +472,20 @@ sub post_with_cache_p { say ' cache miss'; } - $self->{ua}->post_p( $url, $self->{post} )->then( + my $headers = {}; + my $service_desc = $hafas_instance->{ $self->{active_service} }; + + if ( $service_desc->{ua_string} ) { + $headers->{'User-Agent'} = $service_desc->{ua_string}; + } + if ( my $geoip_service = $service_desc->{geoip_lock} ) { + if ( my $proxy = $ENV{"HAFAS_PROXY_${geoip_service}"} ) { + $self->{ua}->proxy->http($proxy); + $self->{ua}->proxy->https($proxy); + } + } + + $self->{ua}->post_p( $url, $headers, $self->{post} )->then( sub { my ($tx) = @_; if ( my $err = $tx->error ) { -- cgit v1.2.3