Problem/Motivation

content_translation_page_attachments() adds alternate links to the html head. However these links also end up in the response headers. The large header size crashes the webserver.

The HTTP Link entity-header field provides a means for serializing one or more links in HTTP headers. It is semantically equivalent to the HTML
element.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link

The first bytes in a response are important from a performance perspective. Link response headers are semantically equivalent to the HTML <link> element, so these links should not be available in both the response headers and HTML <link> elements

Proposed resolution

Remove rel="alternate" links from the response headers.

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

rel="alternate" links provided by the Content Translation module were added as both link HTTP headers and link HTML tags, but are now added only as link HTML tags.

Original report by swentel

content_translation_page_attachments() adds alternate links to the html head, which is fine. However these links also end up in the response headers (I honestly don't really understand why we do that). Now, when there are too many languages (in our case, we're working with 47), varnish will crash with a 503.

-   BogoHeader     Too many headers: Vary: Accept-Encodin
-   HttpGarbage    "HTTP/1.1%00200%00OK%00%0aDate: Fri, 28 Apr 2017 12:54:20 GMT%00%0aServer: Apache/2.4.12 (Ubuntu)%00%0aX-Powered-By: PHP/5.6.20%00%0aCache-Control: must-revalidate, no-cache, private%00%0aLink: <http://127.0.0.1:6081/en/handbook>; rel="alternate"; hreflang="en"%00%0aLink: <http://12%00"
-   BerespStatus   503
-   BerespReason   Service Unavailable
-   FetchError     http format error
-   BackendClose   17 default(127.0.0.1,,80)
-   Timestamp      Beresp: 1493384064.185137 3.703384 3.703163
-   Timestamp      Error: 1493384064.185146 3.703393 0.000010
-   BerespProtocol HTTP/1.1
-   BerespStatus   503

I've altered out these alternate links for now with hook_module_implements_alter(). But we shouldn't send those to varnish IMO.

/**
 * Implements hook_module_implements_alter().
 */
function module_module_implements_alter(&$implementations, $hook) {
  if ($hook == 'page_attachments') {
    unset($implementations['content_translation']);
  }
}

Comments

swentel created an issue. See original summary.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

swentel’s picture

Component: content_translation.module » base system

Actually this not related to content translation alone - I think we should really stop sending any rel link along with the headers.

Moving to another component for now to get more discussion.

ekes’s picture

Noticed Acquia suffering this one https://library.acquia.com/article/varnish-header-limits as will everyone who can't change their Varnish runtime parameters https://www.varnish-cache.org/docs/5.0/reference/varnishd.html#run-time-...

andypost’s picture

that affects nginx as well, requiring to increase buffers

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

raphaeltbm’s picture

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

aangel’s picture

Title: With many languages, content_translation_page_attachments adds to many alternate links to the reponse headers crashing varnish (503) » With many languages, content_translation_page_attachments adds too many alternate links to the response headers crashing varnish (503)

It's blowing our Varnish, too, with 37 languages. This article says that it's valid to put in the HTTP header but it seems the <head> or site map are the better places for it to avoid this problem.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

leolandotan’s picture

We are also having this issue and we have 90 plus translations enabled. Is that safe for SEO or for whatever functionality to unset is as suggested (`unset($implementations['content_translation']);`)?

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

idebr’s picture

Status: Active » Needs review
StatusFileSize
new1.08 KB

The HTTP Link entity-header field provides a means for serializing one or more links in HTTP headers. It is semantically equivalent to the HTML
element.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link

The first bytes in a response are important from a performance perspective. If Link response headers are semantically equivalent to the HTML <link> element, why should these links be available in both the response headers and HTML <link> elements?

Attached patch from the links from the response headers.

Status: Needs review » Needs work

The last submitted patch, 17: 2873648-17.patch, failed testing. View results

mfb’s picture

Maybe just keep the canonical link header for now - although it should be fine to remove (as far as I can tell), it's not what this issue is about and is not causing nearly as many problems as Content Translation's link headers.

idebr’s picture

Status: Needs work » Needs review
StatusFileSize
new638 bytes
new1.7 KB

Attached patch updates test coverage for the response headers.

mfb’s picture

Can you explain the rationale for removing the canonical link header while keeping the shortlink header? Is shortlink somehow more useful while canonical is not?

idebr’s picture

StatusFileSize
new1.42 KB
new2.29 KB

#21 The rel="shortlink" did not show up in my project's response headers since it was already being removed by the Metatag module

Attached patch also removes the duplicate response header for rel="shortlink"

mfb’s picture

Status: Needs review » Needs work

Looks like unused use statement is triggering a failure

mfb’s picture

Created a draft change record: https://www.drupal.org/node/3266120

andregp’s picture

Status: Needs work » Needs review
StatusFileSize
new2.43 KB
new1.51 KB

Removed unused use statement.

mfb’s picture

Status: Needs review » Reviewed & tested by the community

Great!

(It didn't even make sense to Html::escape() the URL, as HTTP headers are not HTML - issue for that is #3245895: Link HTTP header should not be HTML-encoded.)

I'm not aware of any use for these link HTTP headers so marking RTBC.

If anyone does have a use case for the canonical and shortlink HTTP headers, we can always fall back on just getting rid of Content Translation's HTTP headers.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

I think we need to be a little bit careful here. The varnish crash is bad and we need to fix that but we've been emitting these link headers for a long time so surely someone somewhere is depending on them. We added this in #552478: Restrict "self-closing" tags to only void elements in drupal_pre_render_html_tag. I think falling back to remove the translations is probably for the best because the unlimited nature of that is what is causing the problem.

catch’s picture

Issue tags: +Needs follow-up

Let's open a follow-up to remove the other links - but that could happen as a 10.x-only behaviour change maybe just in case someone actually is relying on them somewhere.

alexpott’s picture

Trying to work out who uses this. Apparently Google added support for this to there search engine indexing in 2011. I think the primary use-case was for

giving webmasters yet another avenue to provide a preferred URL for non-text/html content-types such as PDF files

Source: https://moz.com/blog/how-to-advanced-relcanonical-http-headers

I think we should open a follow to discuss remove the canonical and shortlink because as someone said on the internet:

Because it’s relatively easy to implement rel=canonical tags in a page’s HTML, it’s rare to find canonical links sent as part of a page’s HTTP response. However, it’s always worth double-checking the page’s HTTP headers for canonical links, especially if you see unusual indexing and ranking issues on a website.

Source: https://searchengineland.com/the-ultimate-guide-to-http-status-codes-and...

idebr’s picture

Issue summary: View changes
Issue tags: -Needs follow-up
idebr’s picture

Issue summary: View changes
idebr’s picture

Status: Needs work » Needs review
StatusFileSize
new514 bytes

Attached patch removes rel="alternate" links from the response headers.

wim leers’s picture

Component: base system » content_translation.module
Status: Needs review » Reviewed & tested by the community
Issue tags: +front-end performance

The first bytes in a response are important from a performance perspective. If Link response headers are semantically equivalent to the HTML <link> element, why should these links be available in both the response headers and HTML <link> elements?

— @idebr in #17

This 100% convinces me, no matter the hypermedia impact.

A change record already exists.

alexpott’s picture

Version: 9.4.x-dev » 9.3.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed and pushed 7af29a9e52 to 10.0.x and 3c6394a483 to 9.4.x. Thanks!

I think it is telling that the addition of the translation links to the HTTP response is completely untested.

Going to ping @catch because I think we should consider backporting this to 9.3.x

  • alexpott committed 7af29a9 on 10.0.x
    Issue #2873648 by idebr, andregp, mfb, swentel: With many languages,...

  • alexpott committed 3c6394a on 9.4.x
    Issue #2873648 by idebr, andregp, mfb, swentel: With many languages,...
catch’s picture

Given this fixes a 5** error, it's a one-liner, and I don't personally see any reason anyone would rely on these in any way that would break by removing them, I think this is a good candidate for backport. Although maybe better after this Wednesday's release just to give us time to change our minds.

wim leers’s picture

Version: 9.3.x-dev » 9.4.x-dev
Status: Patch (to be ported) » Fixed

Given that 9.4.0-beta1 will be released today, marking this as Fixed and moving back to 9.4.x.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.