-
-
Notifications
You must be signed in to change notification settings - Fork 16.3k
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
HTML in the res.redirect()
method is missing a DOCTYPE
and <title>
element
#5058
Comments
Not sure that this is something standard. What is being done by others frameworks / languages? |
I am not familiar with the status of other Node.js frameworks, but the situation of popular web server software is as follows. Apache 2.4
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="https://example.com/">here</a>.</p>
</body></html> nginx 1.23
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.23.3</center>
</body>
</html> |
Hi @SaekiTominaga thank you for that! Those seem to have a lot more parts than your initial recommendation. So in order to understand the issue, can you provide us the details of what clients are not able to render the response from express? This will better help guide the conversation by having the information regarding which clients/browsers are having an issue with the response from Express and thus we can work to make sure and validate that any changes made will resolve the issue. |
Hi, @dougwilson ! Currently, most browsers automatically redirect when a
Code#1 ( app.get('/twitter', (req, res) => {
res.redirect(301, 'https://twitter.com/');
}); * The redirect process itself works fine. This is just a measure to prevent user confusion by displaying the page title in the browser tab by adding the |
The response body of a redirect via the
res.redirect()
method will be<p>${statuses.message[status]} Redirecting to <a href="${url}">${url}</a></p>
, which is invalid HTML without aDOCTYPE
and<title>
element.In particular, the absence of a
<title>
element is detrimental to the user.RFC 9110, 15.4. Redirection 3xx, states that the user agent behavior when the
Location
header field is set with status code 3xx is "the user agent MAY automatically redirect its request to the URI".Note that it is MAY.
And in fact, depending on the user's environment, automatic redirection may not occur and the contents of the response body may be displayed on the screen.
In the old days, there was an option to disable redirects in Presto Opera's advanced settings.
Even now, when Android Firefox redirects to an app-linked URL with 3xx, the app is automatically launched, but the browser screen still displays the 3xx response body.
Therefore, it would be desirable to set the
DOCTYPE
and<title>
element even for 3xx screens.Improvement plan
express/lib/response.js
Line 963 in 8368dc1
↓
The text was updated successfully, but these errors were encountered: