Skip to content

Instantly share code, notes, and snippets.

@bellbind
Created June 11, 2014 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bellbind/c5712dd845ccc56d9721 to your computer and use it in GitHub Desktop.
Save bellbind/c5712dd845ccc56d9721 to your computer and use it in GitHub Desktop.
[nodejs][http]Check 308 Permanent Redirect on browsers
var http = require("http");
// see: http://tools.ietf.org/html/rfc7238
if (!http.STATUS_CODES["308"]) http.STATUS_CODES["308"] = "Permanent Redirect";
var server = http.createServer(function (req, res) {
if (req.url === "/redirect") {
var uri = "http://" + req.headers["host"] + "/result";
res.statusCode = 308;
res.setHeader("Location", uri);
return res.end("<body>Your browser not suppported " +
"308 Permanent Redirect</body>");
} else if (req.url === "/result") {
//process.stdout.pipe(req);
return res.end("<body><h1>Result</h1>" +
"<div>Access method: " + req.method + "</div>"+
"<div><a href='/'>back</a></div></body>");
} else {
return res.end("<body><h1>Check 308 Permanent Redirect</h1>" +
"<form method='POST' action='/redirect'>" +
"Do <button type='submit'>POST</button></form> " +
"or <a href='/redirect'>GET</a></body>");
}
});
server.listen(3000);
@bellbind
Copy link
Author

  • firefox 30: supported with confirmation when POST redirect
  • chrome 35.0.1916.153: not supported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment