Bug 756165 - Return close code 1015 to JS when TLS setup fails, r=baku, r=valentin

We cannot simply pass the status code using nsIWebSocketListener::OnServerClose because it's called only when the connection is established. Instead, I'm passing TLS failure from http channel to nsIWebSocketListener::OnStop where the correct status code is set.
This commit is contained in:
Michal Novotny
2018-06-27 06:50:00 +03:00
parent 4f9786d789
commit d411e9bebc
2 changed files with 29 additions and 2 deletions

View File

@@ -59,6 +59,7 @@
#include "mozilla/Telemetry.h"
#include "mozilla/TimeStamp.h"
#include "nsSocketTransportService2.h"
#include "nsINSSErrorsService.h"
#include "plbase64.h"
#include "prmem.h"
@@ -3817,9 +3818,25 @@ WebSocketChannel::OnStartRequest(nsIRequest *aRequest,
rv = mHttpChannel->GetResponseStatus(&status);
if (NS_FAILED(rv)) {
nsresult httpStatus;
rv = NS_ERROR_CONNECTION_REFUSED;
// If we failed to connect due to unsuccessful TLS handshake, we must
// propagate that error to mozilla::dom::WebSocketImpl so it can set
// status code to 1015. Otherwise return NS_ERROR_CONNECTION_REFUSED.
if (NS_SUCCEEDED(mHttpChannel->GetStatus(&httpStatus))) {
uint32_t errorClass;
nsCOMPtr<nsINSSErrorsService> errSvc =
do_GetService("@mozilla.org/nss_errors_service;1");
// If GetErrorClass succeeds httpStatus is TLS related failure.
if (errSvc && NS_SUCCEEDED(errSvc->GetErrorClass(httpStatus, &errorClass))) {
rv = httpStatus;
}
}
LOG(("WebSocketChannel::OnStartRequest: No HTTP Response\n"));
AbortSession(NS_ERROR_CONNECTION_REFUSED);
return NS_ERROR_CONNECTION_REFUSED;
AbortSession(rv);
return rv;
}
LOG(("WebSocketChannel::OnStartRequest: HTTP status %d\n", status));