Created
June 11, 2014 07:24
-
-
Save bellbind/c5712dd845ccc56d9721 to your computer and use it in GitHub Desktop.
[nodejs][http]Check 308 Permanent Redirect on browsers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Author
bellbind
commented
Jun 11, 2014
- 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