Skip to content

Commit

Permalink
Prefer https for canonical URLs.
Browse files Browse the repository at this point in the history
  • Loading branch information
benmwebb committed Sep 11, 2015
1 parent b80189f commit 472329b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion perl/saliweb/frontend.pm
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,8 @@ sub get_start_html_parameters {
-code => $JS_Google_Analytics}]);
my $canon = $self->{canonical_url};
if (defined $canon) {
$canon =~ s/^https:/http:/;
# Prefer https for canonical URLs
$canon =~ s/^http:/https:/;
$param{-head} = $q->Link({-rel=>'canonical', -href=>$canon});
}
return %param;
Expand Down
9 changes: 7 additions & 2 deletions test/frontend/frontend.pl
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,8 @@ END

sub make_test_frontend {
my $self = {CGI=>new CGI, page_title=>'test title',
rate_limit_checked=>0, server_name=>shift, cgiroot=>'/foo',
canonical_url=>'/foo'};
rate_limit_checked=>0, server_name=>shift,
cgiroot=>'http://foo/bar'};
bless($self, 'Dummy::Frontend');
return $self;
}
Expand All @@ -451,6 +451,11 @@ sub test_display_page {
"<title>$title<\/title>.*<body.*Link 1.*Project menu for.*" .
"test_${page_type}_page.*<\/html>/s",
"$sub generates valid complete HTML page");
if ($page_type eq "index") {
like($out, "/<head>.*<link rel=\"canonical\" " .
"href=\"https://foo/bar/\" />.*</head>/s",
"$sub adds canonical link");
}

$self = make_test_frontend("access${page_type}");
$out = stdout_from { $self->$sub() };
Expand Down

0 comments on commit 472329b

Please sign in to comment.