DDG
view release on metacpan or search on metacpan
lib/DDG/Rewrite.pm view on Meta::CPAN
if (defined $ENV{$_}) {
my $val = $ENV{$_};
$to =~ s/\Q{{ENV{$_}}}/$val/g;
} else {
push @missing_envs, $_;
$to =~ s/\Q{{ENV{$_}}}//g;
}
}
$self->_missing_envs(\@missing_envs) if @missing_envs;
$self->_parsed_to($to);
}
has path => (
is => 'ro',
required => 1,
);
has to => (
is => 'ro',
required => 1,
);
has from => (
is => 'ro',
predicate => 'has_from',
);
has callback => (
is => 'ro',
predicate => 'has_callback',
);
has wrap_jsonp_callback => (
is => 'ro',
default => sub { 0 },
);
has wrap_string_callback => (
is => 'ro',
default => sub { 0 },
);
has headers => (
is => 'ro',
predicate => 'has_headers',
);
has proxy_cache_valid => (
is => 'ro',
predicate => 'has_proxy_cache_valid',
);
has proxy_ssl_session_reuse => (
is => 'ro',
predicate => 'has_proxy_ssl_session_reuse',
);
has proxy_x_forwarded_for => (
is => 'ro',
default => sub { 'X-Forwarded-For $proxy_add_x_forwarded_for' }
);
has post_body => (
is => 'ro',
predicate => 'has_post_body',
);
has nginx_conf => (
is => 'ro',
lazy => 1,
builder => '_build_nginx_conf',
);
has error_fallback => (
is => 'rw',
default => sub { 0 },
);
has upstream_timeouts => (
is => 'lazy',
predicate => 'has_upstream_timeouts',
default => sub { +{} },
);
has content_type_javascript => (
is => 'ro',
default => sub { 0 },
);
sub _build_nginx_conf {
my ( $self ) = @_;
my $uri = URI->new($self->parsed_to);
my $host = $uri->host;
my $port = $uri->port;
my $scheme = $uri->scheme;
my $uri_path = $self->parsed_to;
$uri_path =~ s!$scheme://$host:$port!!;
$uri_path =~ s!$scheme://$host!!;
my $is_duckduckgo = $host =~ /(?:127\.0\.0\.1|duckduckgo\.com)/;
# wrap various other things into jsonp
croak "Cannot use wrap_jsonp_callback and wrap_string callback at the same time!" if $self->wrap_jsonp_callback && $self->wrap_string_callback;
my $wrap_jsonp_callback = $self->has_callback && $self->wrap_jsonp_callback;
my $wrap_string_callback = $self->has_callback && $self->wrap_string_callback;
my $uses_echo_module = $wrap_jsonp_callback || $wrap_string_callback;
my $content_type_javascript = $self->content_type_javascript;
my $callback = $self->callback;
my ($spice_name) = $self->path =~ m{^/js/spice/(.+)/$};
$spice_name =~ s|/|_|og if $spice_name;
my $cfg = "location ^~ ".$self->path." {\n";
my $timeouts = $self->has_upstream_timeouts && $self->upstream_timeouts;
if (ref $timeouts eq 'HASH' && keys %$timeouts) {
$cfg .= "\tproxy_connect_timeout $timeouts->{connect};\n" if $timeouts->{connect};
$cfg .= "\tproxy_send_timeout $timeouts->{send};\n" if $timeouts->{send};
$cfg .= "\tproxy_read_timeout $timeouts->{read};\n" if $timeouts->{read};
}
( run in 1.620 second using v1.01-cache-2.11-cpan-6aa56a78535 )