Skip to content

Instantly share code, notes, and snippets.

@SwagColoredKitteh
Last active January 22, 2017 09:59
Show Gist options
  • Save SwagColoredKitteh/2c24c7fac635445042eda4a30e10420e to your computer and use it in GitHub Desktop.
Save SwagColoredKitteh/2c24c7fac635445042eda4a30e10420e to your computer and use it in GitHub Desktop.
Reproduce the issue that two out-of-order responses for the same <link> element in servo will apply the wrong stylesheet
<!DOCTYPE html>
<html>
<head>
<title>The fabulous always-green webpage</title>
</head>
<body>
<script>
var link = document.createElement("link");
link.rel = "stylesheet";
document.head.appendChild(link);
link.href = "main.css";
link.href = "alternate.css";
</script>
</body>
</html>
"use strict";
const http = require("http");
const fs = require("fs");
let last = undefined;
const FILES = {
"/main.css": "body { background-color: #F00; }",
"/alternate.css": "body { background-color: #0F0; }",
"/": fs.readFileSync("issue.html")
};
const DELAYED = ["/main.css", "/alternate.css"];
function handleRequest(req, res) {
if(FILES.hasOwnProperty(req.url)) {
const sp = req.url.split(".");
const ext = sp[sp.length - 1];
if(ext === "css") {
res.setHeader("Content-Type", "text/css");
}
else {
res.setHeader("Content-Type", "text/html");
}
res.end(FILES[req.url]);
}
else {
res.end("");
}
}
http.createServer((req, res) => {
console.log("req", req.url);
if(DELAYED.indexOf(req.url) == -1) {
handleRequest(req, res);
}
else if(last === undefined) {
last = {req, res};
}
else {
handleRequest(req, res);
const lastReq = last.req;
const lastRes = last.res;
setTimeout(() => handleRequest(lastReq, lastRes), 10);
last = undefined;
}
}).listen(8080);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment