Permalink
Browse files

Display the canonical header names in the 'Components' tab (when the …

…magnifying glass is clicked).
  • Loading branch information...
1 parent c2d7d78 commit 7e1357f4a31beacbff87d90c60d5201291d6ec78 @papandreou papandreou committed Feb 17, 2012
Showing with 34 additions and 2 deletions.
  1. +2 −2 src/common/renderers.js
  2. +32 −0 src/common/util.js
View
4 src/common/renderers.js
@@ -155,7 +155,7 @@ YSLOW.renderer = {
for (field in comp.headers) {
if (comp.headers.hasOwnProperty(field) && comp.headers[field]) {
sText += '<tr><td class="param-name">' +
- YSLOW.util.escapeHtml(field) +
+ YSLOW.util.escapeHtml(YSLOW.util.formatHeaderName(field)) +
'</td><td class="param-value">' +
YSLOW.util.escapeHtml(comp.headers[field]) +
'</td></tr>';
@@ -168,7 +168,7 @@ YSLOW.renderer = {
if (comp.req_headers.hasOwnProperty(field) &&
comp.req_headers[field]) {
sText += '<tr><td class="param-name">' +
- YSLOW.util.escapeHtml(field) +
+ YSLOW.util.escapeHtml(YSLOW.util.formatHeaderName(field)) +
'</td><td class="param-value"><p>' +
YSLOW.util.escapeHtml(comp.req_headers[field]) +
'</p></td></tr>';
View
32 src/common/util.js
@@ -566,6 +566,38 @@ YSLOW.util = {
},
/**
+ * Convert a HTTP header name to its canonical form,
+ * e.g. "content-length" => "Content-Length".
+ * @param headerName the header name (case insensitive)
+ * @return {String} the formatted header name
+ */
+ formatHeaderName: (function () {
+ var specialCases = {
+ 'content-md5': 'Content-MD5',
+ dnt: 'DNT',
+ etag: 'ETag',
+ p3p: 'P3P',
+ te: 'TE',
+ 'www-authenticate': 'WWW-Authenticate',
+ 'x-att-deviceid': 'X-ATT-DeviceId',
+ 'x-cdn': 'X-CDN',
+ 'x-ua-compatible': 'X-UA-Compatible',
+ 'x-xss-protection': 'X-XSS-Protection'
+ };
+ return function (headerName) {
+ var lowerCasedHeaderName = headerName.toLowerCase();
+ if (specialCases.hasOwnProperty(lowerCasedHeaderName)) {
+ return specialCases[lowerCasedHeaderName];
+ } else {
+ // Make sure that the first char and all chars following a dash are upper-case:
+ return lowerCasedHeaderName.replace(/(^|-)([a-z])/g, function ($0, optionalLeadingDash, ch) {
+ return optionalLeadingDash + ch.toUpperCase();
+ });
+ }
+ };
+ }()),
+
+ /**
* Math mod method.
* @param {Number} divisee
* @param {Number} base

0 comments on commit 7e1357f

Please sign in to comment.