[英]Mixed content & uri_for function
We have an web application using dancer2 framework.The website is using https. But in the page, it calls other page using uri_for.我们有一个使用 dancer2 框架的 web 应用程序。该网站使用 https。但在页面中,它使用 uri_for 调用其他页面。 ie The url is generated by uri_for and sending it to template.即 url 由 uri_for 生成并将其发送到模板。
The url generated is automatically set 'http', so the page has mixed content.生成的url自动设置为'http',所以页面内容混杂。 And thus doesn't load.因此不会加载。
My question is where is the uri_for located.我的问题是 uri_for 位于何处。 Why is automatically set 'http', how can I specify it to be 'https'?为什么自动设置为'http',如何指定为'https'?
Many thanks Wendy非常感谢温迪
My question is where is the
uri_for
located.我的问题是uri_for
位于何处。
See line 283 in Dancer2::Core::Request
:参见Dancer2::Core::Request
中的第 283 行:
sub uri_for {
my ( $self, $part, $params, $dont_escape ) = @_;
$part ||= '';
my $uri = $self->base;
# Make sure there's exactly one slash between the base and the new part
my $base = $uri->path;
$base =~ s|/$||;
$part =~ s|^/||;
$uri->path("$base/$part");
$uri->query_form($params) if $params;
return $dont_escape
? uri_unescape( ${ $uri->canonical } )
: ${ $uri->canonical };
}
It obtains the scheme by calling $self->base
, see line 242 :它通过调用$self->base
获得方案,参见第 242 行:
sub base {
my $self = shift;
my $uri = $self->_common_uri;
return $uri->canonical;
}
which calls $self->_common_uri
(see line 249 ):它调用$self->_common_uri
(参见第 249 行):
sub _common_uri {
my $self = shift;
my $path = $self->env->{SCRIPT_NAME};
my $port = $self->env->{SERVER_PORT};
my $server = $self->env->{SERVER_NAME};
my $host = $self->host;
my $scheme = $self->scheme;
my $uri = URI->new;
$uri->scheme($scheme);
$uri->authority( $host || "$server:$port" );
$uri->path( $path || '/' );
return $uri;
}
which calls $self->scheme
, see line 159 :调用$self->scheme
,见第 159 行:
sub scheme {
my ($self) = @_;
my $scheme = $self->is_behind_proxy
? $self->forwarded_protocol
: '';
return $scheme || $self->env->{'psgi.url_scheme'};
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.