зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1849641
- log a console message and use a more descriptive error code when HTTP response status line cannot be parsed; r=valentin,necko-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D186705
This commit is contained in:
Родитель
5d9a192aa9
Коммит
b400c852ad
|
@ -92,3 +92,5 @@ APIDeprecationWarning=Warning: ‘%1$S’ deprecated, please use ‘%2$S’
|
|||
# LOCALIZATION NOTE (ResourceBlockedCORS): %1$S is the url of the resource blocked by ORB. $2$S is the reason.
|
||||
# example: The resource at <url> was blocked by OpaqueResponseBlocking. Reason: “nosniff with either blocklisted or text/plain”.
|
||||
ResourceBlockedORB=The resource at “%1$S” was blocked by OpaqueResponseBlocking. Reason: “%2$S”.
|
||||
|
||||
InvalidHTTPResponseStatusLine=The status line of the HTTP response is invalid
|
||||
|
|
|
@ -7395,6 +7395,31 @@ static nsLiteralCString ContentTypeToTelemetryLabel(nsHttpChannel* aChannel) {
|
|||
return "other"_ns;
|
||||
}
|
||||
|
||||
nsresult nsHttpChannel::LogConsoleError(const char* aTag) {
|
||||
nsCOMPtr<nsIConsoleService> console(
|
||||
do_GetService(NS_CONSOLESERVICE_CONTRACTID));
|
||||
NS_ENSURE_TRUE(console, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
nsCOMPtr<nsILoadInfo> loadInfo = LoadInfo();
|
||||
NS_ENSURE_TRUE(console, NS_ERROR_OUT_OF_MEMORY);
|
||||
uint64_t innerWindowID = loadInfo->GetInnerWindowID();
|
||||
|
||||
nsAutoString errorText;
|
||||
nsresult rv = nsContentUtils::GetLocalizedString(
|
||||
nsContentUtils::eNECKO_PROPERTIES, aTag, errorText);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIScriptError> error(do_CreateInstance(NS_SCRIPTERROR_CONTRACTID));
|
||||
NS_ENSURE_TRUE(error, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
rv = error->InitWithSourceURI(errorText, mURI, u""_ns, 0, 0,
|
||||
nsIScriptError::errorFlag,
|
||||
"Invalid HTTP Status Lines"_ns, innerWindowID);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
console->LogMessage(error);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHttpChannel::OnStopRequest(nsIRequest* request, nsresult status) {
|
||||
AUTO_PROFILER_LABEL("nsHttpChannel::OnStopRequest", NETWORK);
|
||||
|
@ -7408,6 +7433,10 @@ nsHttpChannel::OnStopRequest(nsIRequest* request, nsresult status) {
|
|||
MOZ_ASSERT(NS_IsMainThread(),
|
||||
"OnStopRequest should only be called from the main thread");
|
||||
|
||||
if (mStatus == NS_ERROR_PARSING_HTTP_STATUS_LINE) {
|
||||
Unused << LogConsoleError("InvalidHTTPResponseStatusLine");
|
||||
}
|
||||
|
||||
if (WRONG_RACING_RESPONSE_SOURCE(request)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -794,6 +794,8 @@ class nsHttpChannel final : public HttpBaseChannel,
|
|||
nsresult TriggerNetwork();
|
||||
void CancelNetworkRequest(nsresult aStatus);
|
||||
|
||||
nsresult LogConsoleError(const char* aTag);
|
||||
|
||||
void SetHTTPSSVCRecord(already_AddRefed<nsIDNSHTTPSSVCRecord>&& aRecord);
|
||||
|
||||
// Timer used to delay the network request, or to trigger the network
|
||||
|
|
|
@ -378,7 +378,7 @@ nsresult nsHttpResponseHead::ParseStatusLine_locked(const nsACString& line) {
|
|||
const char* p = start + index + 1;
|
||||
while (p < end && NS_IsHTTPWhitespace(*p)) ++p;
|
||||
if (p == end || !mozilla::IsAsciiDigit(*p)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
return NS_ERROR_PARSING_HTTP_STATUS_LINE;
|
||||
}
|
||||
const char* codeStart = p;
|
||||
while (p < end && mozilla::IsAsciiDigit(*p)) ++p;
|
||||
|
@ -386,7 +386,7 @@ nsresult nsHttpResponseHead::ParseStatusLine_locked(const nsACString& line) {
|
|||
// Only accept 3 digits (including all leading zeros)
|
||||
// Also if next char isn't whitespace, fail (ie, code is 0x2)
|
||||
if (p - codeStart > 3 || (p < end && !NS_IsHTTPWhitespace(*p))) {
|
||||
return NS_ERROR_FAILURE;
|
||||
return NS_ERROR_PARSING_HTTP_STATUS_LINE;
|
||||
}
|
||||
|
||||
// At this point the code is between 0 and 999 inclusive
|
||||
|
@ -394,7 +394,7 @@ nsresult nsHttpResponseHead::ParseStatusLine_locked(const nsACString& line) {
|
|||
nsresult rv;
|
||||
mStatus = strCode.ToInteger(&rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
return NS_ERROR_PARSING_HTTP_STATUS_LINE;
|
||||
}
|
||||
|
||||
// Reason-Phrase: whatever remains after any whitespace (even empty)
|
||||
|
|
|
@ -344,6 +344,8 @@ with modules["NETWORK"]:
|
|||
errors["NS_ERROR_NON_LOCAL_CONNECTION_REFUSED"] = FAILURE(88)
|
||||
# Connection to a sts host without a hsts header.
|
||||
errors["NS_ERROR_BAD_HSTS_CERT"] = FAILURE(89)
|
||||
# Error parsing the status line of an HTTP response
|
||||
errors["NS_ERROR_PARSING_HTTP_STATUS_LINE"] = FAILURE(90)
|
||||
|
||||
# XXX really need to better rationalize these error codes. are consumers of
|
||||
# necko really expected to know how to discern the meaning of these??
|
||||
|
|
Загрузка…
Ссылка в новой задаче