Closed Bug 1720030 Opened 4 years ago Closed 4 years ago

MIME Content-type using router.php gives warning in FF, but not in Chrome

Categories

(DevTools :: Netmonitor, defect)

Firefox 89
defect

Tracking

(Not tracked)

RESOLVED INVALID

People

(Reporter: t20, Unassigned)

Details

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0

Steps to reproduce:

On local Windows development server:

File .htaccess:

RewriteEngine On
RewriteRule ^(.*)$ router.php [END,QSA]

File router.php:

<?php
$pathDR=@$_SERVER["REDIRECT_URL"];
$pathFS=$_SERVER["DOCUMENT_ROOT"].$pathDR;

if (stripos($pathDR,".js")!==false)
	{
	header('text/javascript');
	require $pathFS;
	exit;
	}
require $pathFS;
?>
~~~

File t.js:

alert("In t.js");

File t.php:

<!DOCTYPE html>
<html lang="en">
...
<body>
<h2>Test</h2>
<script src="t.js"></script>
</body>
</html>

Test address for browser:

http://localhost/nsr5-test/t.php




Actual results:

Result in Console:

"Warnimg: The script from “http://localhost/nsr5-test/t.js” was loaded even though its MIME type (“text/html”) is not a valid JavaScript MIME type. "

Result in Network:

t.js: type: html (instead of JavaScript)

Result in Chrome:

t.js: type: script (no warning message)
Content-Type: text/html; charset=UTF-8



Expected results:

Problem 1: t.js response header seen as being of html type when there is a 'text/javascript' PHP header.

Problem 2: warning in Firefox, no warning in Chrome

The Bugbug bot thinks this bug should belong to the 'Core::DOM: Core & HTML' component, and is moving the bug to that component. Please revert this change in case you think the bot is wrong.

Component: Untriaged → DOM: Core & HTML
Product: Firefox → Core

The warning is correct, because the Content-Type header is of an invalid type ("text/html" here) for script. Chrome is free not to warn about this.

I am not sure if the type in the devtools, if it should indicate the goal or the Content-Type.

Component: DOM: Core & HTML → Netmonitor
Product: Core → DevTools

I'm puzzled. Am I allowed to ask why the Content-Type got set incorrectly, when router.php set it correctly as text/javascript?

Presumably the code in router.php isn't doing what you think it's doing.

Shouldn't it be header('Content-Type: text/javascript');

Yes! A further hour of experimentation and failure finally revealed that my code header('text/javascript'); was incorrect. Apparently, there is no header checking to catch this error in Apache, Firefox, or the Web Development Tools, so no error is reported.

The status should be changed to Closed: not a bug and left as a warning to others. Even better, error checking should be added to Firefox.

Status: UNCONFIRMED → RESOLVED
Closed: 4 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.