Problem/Motivation
HtmlResponseAttachmentsProcessor::processHtmlHeadLink() has some problems producing the HTTP Link headers (see http://tools.ietf.org/html/rfc2068#section-19.6.2.4).
1) It produces invalid HTTP Link header. This because in this method the href attribute is unproperly escaped:
$href = '<' . Html::escape($attributes['href'] . '>');
It should be:
$href = '<' . Html::escape($attributes['href']) . '>';
2) It not take in account the separator (";") between link and link param
3) It allow only one Link header (while an entity may include multiple Link values), because it set the flag for replace the Link header instead of merge
$attached['http_header'][] = ['Link', $href . drupal_http_header_attributes($attributes), TRUE];<-- TRUE MEANS REPLACE
This means that only one link is added to headers. This cause a big difference between links in the html head and headers
Html head:
<link rel="shortcut icon" href="http://localhost/drupal8/core/misc/favicon.ico" type="image/vnd.microsoft.icon" />
<link rel="canonical" href="/drupal8/node/1" />
<link rel="shortlink" href="/drupal8/node/1" />
<link rel="delete-form" href="/drupal8/node/1/delete" />
<link rel="edit-form" href="/drupal8/node/1/edit" />
<link rel="version-history" href="/drupal8/node/1/revisions" />
<link rel="revision" href="/drupal8/node/1" />
<link rel="devel-render" href="/drupal8/node/1/devel/render" />
<link rel="devel-load" href="/drupal8/node/1/edit/devel" />
Headers:
Link:</drupal8/node/1/edit/devel> rel="devel-load"
Proposed resolution
Fix it
Comment | File | Size | Author |
---|---|---|---|
#19 | 2585899-19.patch | 4.84 KB | mr.baileys |
#19 | 2585899-19-test-only.patch | 2.81 KB | mr.baileys |
#16 | 2585899-16.patch | 2.03 KB | mr.baileys |
#16 | interdiff.txt | 802 bytes | mr.baileys |
#14 | 2585899-13.patch | 2.27 KB | esod |
Comments
Comment #2
willzyx CreditAttribution: willzyx commentedComment #3
dawehnerIMHO bug fixes are pointless without tests :)
Comment #4
willzyx CreditAttribution: willzyx commenteddawehner, you are completely right :)
Added test coverage for nodes, let me know if we need more test coverage
Comment #6
dawehnerFor sure, this tests the functionality but it also feels like just a reimplementation of the actual code
Comment #7
willzyx CreditAttribution: willzyx commentedSo are you suggesting to initialize the array with the expected value? something like this
Comment #8
dawehneryeah that feels better, if you ask me.
Comment #9
willzyx CreditAttribution: willzyx commentedaddressing #6
Comment #13
esod CreditAttribution: esod at Memorial Sloan Kettering Cancer Center commentedRerolled the patch since 2585899-9.patch won't apply to Drupal 8.2.x
Comment #14
esod CreditAttribution: esod at Memorial Sloan Kettering Cancer Center commentedComment #16
mr.baileysSome of the header links in the current patch's tests have been removed since the patch was created. See #2406533: edit-form, delete-form etc. <link> tags added on /node/{node} are invalid according to W3C Validator.
Rerolled without those links, tests should now pass. Removed the "Needs tests"-tag.
Comment #17
mr.baileysComment #18
dawehnerIn an ideal world we would have a test which is more direct, aka. not be part of node module, as well, node module is just one of the users of the system
Comment #19
mr.baileysThanks @dawehner, added additional test coverage to the already existing HtmlResponseAttachmentsTest. No interdiff since the patch contains additional test coverage, no other changes were made to the previous patch.
Comment #21
SchnWalter CreditAttribution: SchnWalter as a volunteer and commentedI've tested the patch from #19 against 8.2.1 and it works properly.
Comment #22
dawehnerThank you for addressing that test location problem!
Comment #23
NickDickinsonWildeLooks good to my browser/me
Comment #24
alexpottI think for consistency this should be
$href .= '; ' . $param;
Because of
Everything else looks great.
Comment #25
mr.baileys@alexpott:
drupal_http_header_attributes()
already prefixes its return value with a space, so adding an additional one would result in 2 spaces between the link and the first param:Comment #26
Wim LeersVery glad to see this being fixed!
Comment #27
esod CreditAttribution: esod at Memorial Sloan Kettering Cancer Center commentedPatch #19 applies cleanly to our system. HtmlResponseAttachmentsTest passes on my local which runs on Apache. On our dev, which runs on nginx, HtmlResponseAttachmentsTest has 8 fails. At
HTTP response header X-Drupal-Cache with value MISS (or HIT) found, actual value:
neither MISS nor HIT is printing. Where do I look for MISS or HIT in the Response Headers?Comment #28
Wim LeersBack to RTBC per #25.
#27: that sounds like a local environment issue.
Comment #29
alexpottThanks for responding to my concern @mr.baileys - and showing me it was unfounded.
Committed and pushed e24749a to 8.3.x and 5863276 to 8.2.x. Thanks!
Minor code style fix on commit:
Comment #31
Wim LeersSince this is a bug, I think it should also be cherry-picked to 8.2.x?
Comment #32
alexpott@Wim Leers it's there :) http://cgit.drupalcode.org/drupal/commit/?id=5863276
Comment #33
Wim LeersOh weird, it's not showing up in this issue, only the 8.3.x commit is showing up, in #30 :(
Sorry!
Comment #34
esod CreditAttribution: esod at Memorial Sloan Kettering Cancer Center commentedI'm seeing the commit in the 8.2.x branch, but not in drupal-8.2.2.tar.gz
Comment #35
alexpott@esod it'll be in the next patch release of 8.2.x - that's 8.2.3 - 8.2.2 was released before this change was committed.