Skip to content

HTML in the res.redirect() method is missing a DOCTYPE and <title> element #5058

Open
@SaekiTominaga

Description

@SaekiTominaga

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 a DOCTYPE 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

body = '<p>' + statuses.message[status] + '. Redirecting to <a href="' + u + '">' + u + '</a></p>'

body = '<!DOCTYPE html><title>' + statuses.message[status] + '</title><p>' + statuses.message[status] + '. Redirecting to <a href="' + u + '">' + u + '</a></p>'

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions