Skip to content
This repository has been archived by the owner on Apr 21, 2023. It is now read-only.

Commit

Permalink
Don't add an extra canonical header when there is one already, and test
Browse files Browse the repository at this point in the history
our behavior when one exists.

Was motivated by #1238, but I can't
seem to reproduce the behavior Jeff saw.

If anyone has any ideas as to what I am missing, I would appreciate it.
(Still going ahead with this since it does fix one case and adds more tests.)
  • Loading branch information
morlovich committed Jan 21, 2016
1 parent 02e8f7e commit 0195e29
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
13 changes: 13 additions & 0 deletions net/instaweb/rewriter/cache_extender_test.cc
Expand Up @@ -657,6 +657,19 @@ void CacheExtenderTest::TestCanonicalOnFallback(
EXPECT_STREQ(ResponseHeaders::RelCanonicalHeaderValue(
StrCat(kTestDomain, "b.jpg")),
headers.Lookup1(HttpAttributes::kLink));

// Should also propagate existing ones (and not add incompatible ones).
lru_cache()->Clear();
AddToResponse(StrCat(kTestDomain, "b.jpg"),
HttpAttributes::kLink,
ResponseHeaders::RelCanonicalHeaderValue(
StrCat(kTestDomain, "notb.jpg")));
EXPECT_TRUE(
RewriteTestBase::FetchResourceUrl(out_jpeg_url, &content, &headers));

EXPECT_STREQ(ResponseHeaders::RelCanonicalHeaderValue(
StrCat(kTestDomain, "notb.jpg")),
headers.Lookup1(HttpAttributes::kLink));
}

TEST_F(CacheExtenderTest, CanonicalOnFallbackToOtherPageSpeed) {
Expand Down
11 changes: 11 additions & 0 deletions net/instaweb/rewriter/image_rewrite_filter_test.cc
Expand Up @@ -2358,6 +2358,17 @@ TEST_F(ImageRewriteTest, CanonicalOnTimeout) {
EXPECT_STREQ(ResponseHeaders::RelCanonicalHeaderValue(
StrCat(kTestDomain, "a.jpg")),
headers.Lookup1(HttpAttributes::kLink));

// Now try with an existing canonical header. That should be preserved
lru_cache()->Clear();
AddToResponse(StrCat(kTestDomain, "a.jpg"),
HttpAttributes::kLink,
ResponseHeaders::RelCanonicalHeaderValue(
StrCat(kTestDomain, "nota.jpg")));
EXPECT_TRUE(RewriteTestBase::FetchResourceUrl(out_url, &content, &headers));
EXPECT_STREQ(ResponseHeaders::RelCanonicalHeaderValue(
StrCat(kTestDomain, "nota.jpg")),
headers.Lookup1(HttpAttributes::kLink));
}

TEST_F(ImageRewriteTest, HonorNoTransform) {
Expand Down
3 changes: 2 additions & 1 deletion net/instaweb/rewriter/single_rewrite_context.cc
Expand Up @@ -84,7 +84,8 @@ void SingleRewriteContext::Rewrite(int partition_index,

void SingleRewriteContext::AddLinkRelCanonical(
const ResourcePtr& input, ResponseHeaders* output) {
if (output->HasLinkRelCanonical()) {
if (output->HasLinkRelCanonical() ||
input->response_headers()->HasLinkRelCanonical()) {
return;
}

Expand Down

0 comments on commit 0195e29

Please sign in to comment.