Bug 1325876 - Show internal error page for HTTP responses with error codes (4xx, 5xx) and Content-Length: 0 instead of blank page r=manuel,necko-reviewers,fluent-reviewers,jesup,bolsson,valentin,kershaw

Differential Revision: https://phabricator.services.mozilla.com/D220193
This commit is contained in:
Sean
2024-12-16 17:57:16 +00:00
parent f0cee2d3af
commit 5cca00d5b8
10 changed files with 33 additions and 2 deletions

View File

@@ -6,6 +6,7 @@ malformedURI2=Please check that the URL is correct and try again.
fileNotFound=Firefox cant find the file at %S.
fileAccessDenied=The file at %S is not readable.
# %S is replaced by the uri host
httpErrorPage=%S sent back an error.
serverError=%S might have a temporary problem or it could have moved.
dnsNotFound2=We cant connect to the server at %S.
unknownProtocolFound=Firefox doesnt know how to open this address, because one of the following protocols (%S) isnt associated with any program or is not allowed in this context.

View File

@@ -3353,6 +3353,9 @@ nsDocShell::DisplayLoadError(nsresult aError, nsIURI* aURI,
nestedURI = do_QueryInterface(tempURI);
}
error = "unknownProtocolFound";
} else if (NS_ERROR_NET_EMPTY_RESPONSE == aError) {
NS_ENSURE_ARG_POINTER(aURI);
error = "httpErrorPage";
} else if (NS_ERROR_NET_ERROR_RESPONSE == aError) {
NS_ENSURE_ARG_POINTER(aURI);
error = "serverError";
@@ -6102,6 +6105,7 @@ nsresult nsDocShell::FilterStatusForErrorPage(
if (aStatus == NS_ERROR_NET_TIMEOUT ||
aStatus == NS_ERROR_NET_TIMEOUT_EXTERNAL ||
aStatus == NS_ERROR_NET_EMPTY_RESPONSE ||
aStatus == NS_ERROR_NET_ERROR_RESPONSE ||
aStatus == NS_ERROR_PROXY_GATEWAY_TIMEOUT ||
aStatus == NS_ERROR_REDIRECT_LOOP ||

View File

@@ -6,6 +6,7 @@ malformedURI2=Please check that the URL is correct and try again.
fileNotFound=The file %S cannot be found. Please check the location and try again.
fileAccessDenied=The file at %S is not readable.
# %S is replaced by the uri host
httpErrorPage=%S sent back an error.
serverError=%S might have a temporary problem or it could have moved.
dnsNotFound2=%S could not be found. Please check the name and try again.
unknownProtocolFound=One of the following (%S) is not a registered protocol or is not allowed in this context.

View File

@@ -157,6 +157,7 @@ XPC_MSG_DEF(NS_ERROR_NET_TIMEOUT_EXTERNAL , "The request has been canc
XPC_MSG_DEF(NS_ERROR_OFFLINE , "The requested action could not be completed in the offline state")
XPC_MSG_DEF(NS_ERROR_PORT_ACCESS_NOT_ALLOWED , "Establishing a connection to an unsafe or otherwise banned port was prohibited")
XPC_MSG_DEF(NS_ERROR_NET_RESET , "The connection was established, but no data was ever received")
XPC_MSG_DEF(NS_ERROR_NET_EMPTY_RESPONSE , "The connection was established, but the browser received an empty page with an error response")
XPC_MSG_DEF(NS_ERROR_NET_ERROR_RESPONSE , "The connection was established, but the browser received an error response from the server")
XPC_MSG_DEF(NS_ERROR_NET_INTERRUPT , "The connection was established, but the data transfer was interrupted")
XPC_MSG_DEF(NS_ERROR_NET_PARTIAL_TRANSFER , "A transfer was only partially done when it completed")

View File

@@ -46,6 +46,7 @@ const KNOWN_ERROR_TITLE_IDS = new Set([
"unsafeContentType-title",
"netReset-title",
"netTimeout-title",
"httpErrorPage-title",
"serverError-title",
"unknownProtocolFound-title",
"proxyConnectFailure-title",
@@ -717,8 +718,7 @@ function getNetErrorDescParts() {
case "connectionFailure":
case "netInterrupt":
case "netReset":
case "netTimeout":
case "serverError": {
case "netTimeout": {
let errorTags = [
["li", "neterror-load-error-try-again"],
["li", "neterror-load-error-connection"],
@@ -730,6 +730,10 @@ function getNetErrorDescParts() {
return errorTags;
}
case "httpErrorPage": // 4xx
return [["li", "neterror-http-error-page"]];
case "serverError": // 5xx
return [["li", "neterror-load-error-try-again"]];
case "blockedByPolicy":
case "deniedPortAccess":
case "malformedURI":

View File

@@ -129,6 +129,7 @@ contentEncodingError-title = Content Encoding Error
unsafeContentType-title = Unsafe File Type
netReset-title = The connection was reset
netTimeout-title = The connection has timed out
httpErrorPage-title = Looks like theres a problem with this site
serverError-title = Looks like theres a problem with this site
unknownProtocolFound-title = The address wasnt understood
proxyConnectFailure-title = The proxy server is refusing connections

View File

@@ -44,6 +44,8 @@ neterror-load-error-firewall = If your computer or network is protected by a fir
# This warning is only shown on macOS Sequoia and later (see bug 1929377)
neterror-load-osx-permission = If you are trying to load a local network page, please check that { -brand-short-name } has been granted Local Network permissions in the macOS Privacy & Security settings.
neterror-http-error-page = Check to make sure youve typed the website address correctly.
neterror-captive-portal = You must log in to this network before you can access the internet.
# Variables:

View File

@@ -63,6 +63,7 @@ ID01:
- unsafeContentType-title
- netReset-title
- netTimeout-title
- httpErrorPage-title
- serverError-title
- unknownProtocolFound-title
- proxyConnectFailure-title

View File

@@ -131,6 +131,20 @@ NS_IMETHODIMP nsDocumentOpenInfo::OnStartRequest(nsIRequest* request) {
if (204 == responseCode || 205 == responseCode) {
return NS_BINDING_ABORTED;
}
// Bug 1325876: Show internal error page for HTTP responses with error
// codes (4xx, 5xx) and "Content-Length": 0 instead of blank page
int64_t contentLength = 0;
rv = httpChannel->GetContentLength(&contentLength);
if (NS_FAILED(rv) || contentLength <= 0) {
if (responseCode >= 500) {
return NS_ERROR_NET_ERROR_RESPONSE;
}
if (responseCode >= 400) {
return NS_ERROR_NET_EMPTY_RESPONSE;
}
}
}
//

View File

@@ -327,6 +327,8 @@ with modules["NETWORK"]:
errors["NS_ERROR_NET_RESET"] = FAILURE(20)
# The connection was established, but browser received an error response from the server
errors["NS_ERROR_NET_ERROR_RESPONSE"] = FAILURE(35)
# The connection was established, but browser received an empty page with 4xx, 5xx error response
errors["NS_ERROR_NET_EMPTY_RESPONSE"] = FAILURE(36)
# The connection was established, but the data transfer was interrupted.
errors["NS_ERROR_NET_INTERRUPT"] = FAILURE(71)
# The connection attempt to a proxy failed.