Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rule to check the usage of the Content-Type HTTP response header #245

Merged
merged 1 commit into from
Jun 5, 2017
Merged

Conversation

alrra
Copy link
Contributor

@alrra alrra commented Jun 2, 2017

Fix #141

@alrra alrra requested a review from molant June 2, 2017 07:27
description: 'Check usage of `Content-Type` HTTP response header'
},
fixable: 'code',
ignoredCollectors: ['cdp'], // TODO: Remove once #71 and #164 are fixed.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@molant I've tried to work around things, but until this is solved, the tests cannot be made to pass for both collectors.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so what do you need CDP to download automatically to work? favicon.ico always?

Copy link
Contributor Author

@alrra alrra Jun 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so what do you need CDP to download automatically to work?

@molant Either jsdom and CDP both download the favicon.ico, or none do. Right now only CDP sometimes downloads it.


if (nodeName) {

if (nodeName === 'script') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if people are using script tags for other things like templates? Maybe we should check the type (or its absence)?
In the cases I've found the HTML is directly into the script tag so no request will be done (angular, handlebars) but I'm not sure if there is another template or library that downloads something automatically.
E.g.:

<script type="custom/template" src="/mycustomtemplate.html"></script>

And then my custom template library does some magic and downloads the content.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And then my custom template library does some magic and downloads the content.

Funny thing: Firefox and Edge download the content, Chrome doesn't.

Copy link
Contributor Author

@alrra alrra Jun 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: Even if <script type="type/subtype" src="file.extension"></script> is used, if the file content or file extension suggests a different type, I think we should suggest the appropriate media type for that file.


Also, I don't think there will be a lot of cases here, usually <script type="type/subtype">content...</script> is what is used, plus even that should slowly be replaced with the use of <template>.

.pop();

return getMediaTypeBasedOnFileExtension(fileExtension);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we refactor this a bit so this method isn't that long?
I think we should have a separate function per detection strategy and then execute them until one works.
Something similar to:

const detections = [nodeName, fileContent, fileExtension];
const result = detections.some((detection) => {
  return detection(element, resource, body);
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

description: 'Check usage of `Content-Type` HTTP response header'
},
fixable: 'code',
ignoredCollectors: ['cdp'], // TODO: Remove once #71 and #164 are fixed.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so what do you need CDP to download automatically to work? favicon.ico always?

@alrra
Copy link
Contributor Author

alrra commented Jun 5, 2017

@molant This is ready for another review.

@molant molant merged commit 8fb5da7 into webhintio:master Jun 5, 2017
@alrra alrra deleted the fix-141 branch June 6, 2017 05:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants