Bug 1381718 : Dump request when receiving 400 error draft
authorThomas Nguyen <tnguyen@mozilla.com>
Tue, 25 Jul 2017 14:43:11 +0800
changeset 615491 7399cd71a9ee34fc8b7330aabbe531153a935afd
parent 614015 5928d905c0bc0b28f5488b236444c7d7991cf8d4
child 639198 124038ccd3879619f0c1a68af4009e483fbcba16
push id70381
push userbmo:tnguyen@mozilla.com
push dateWed, 26 Jul 2017 02:51:02 +0000
bugs1381718
milestone56.0a1
Bug 1381718 : Dump request when receiving 400 error MozReview-Commit-ID: 1ZFOIRTryiV
toolkit/components/url-classifier/nsUrlClassifierHashCompleter.js
toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp
--- a/toolkit/components/url-classifier/nsUrlClassifierHashCompleter.js
+++ b/toolkit/components/url-classifier/nsUrlClassifierHashCompleter.js
@@ -423,26 +423,26 @@ HashCompleterRequest.prototype = {
     }
   },
 
   // Creates an nsIChannel for the request and fills the body.
   openChannel: function HCR_openChannel() {
     let loadFlags = Ci.nsIChannel.INHIBIT_CACHING |
                     Ci.nsIChannel.LOAD_BYPASS_CACHE;
 
-    let actualGethashUrl = this.gethashUrl;
+    this.actualGethashUrl = this.gethashUrl;
     if (this.isV4) {
       // As per spec, we add the request payload to the gethash url.
-      actualGethashUrl += "&$req=" + this.buildRequestV4();
+      this.actualGethashUrl += "&$req=" + this.buildRequestV4();
     }
 
-    log("actualGethashUrl: " + actualGethashUrl);
+    log("actualGethashUrl: " + this.actualGethashUrl);
 
     let channel = NetUtil.newChannel({
-      uri: actualGethashUrl,
+      uri: this.actualGethashUrl,
       loadUsingSystemPrincipal: true
     });
     channel.loadFlags = loadFlags;
     channel.loadInfo.originAttributes = {
       // The firstPartyDomain value should sync with NECKO_SAFEBROWSING_FIRST_PARTY_DOMAIN
       // defined in nsNetUtil.h.
       firstPartyDomain: "safebrowsing.86868755-6b82-4842-b301-72671a0db32e.mozilla"
     };
@@ -760,16 +760,21 @@ HashCompleterRequest.prototype = {
         aStatusCode = Cr.NS_ERROR_ABORT;
       }
     }
     let success = Components.isSuccessCode(aStatusCode);
     log('Received a ' + httpStatus + ' status code from the gethash server (success=' + success + ').');
 
     Services.telemetry.getKeyedHistogramById("URLCLASSIFIER_COMPLETE_REMOTE_STATUS2").
       add(this.telemetryProvider, httpStatusToBucket(httpStatus));
+    if (httpStatus == 400) {
+      dump("Safe Browsing server returned a 400 during completion: request= " +
+           this.actualGethashUrl + "\n");
+    }
+
     Services.telemetry.getKeyedHistogramById("URLCLASSIFIER_COMPLETE_TIMEOUT2").
       add(this.telemetryProvider, 0);
 
     // Notify the RequestBackoff once a response is received.
     this._completer.finishRequest(this.gethashUrl, httpStatus);
 
     if (success) {
       try {
--- a/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp
@@ -761,16 +761,27 @@ nsUrlClassifierStreamUpdater::OnStartReq
       rv = httpChannel->GetRequestSucceeded(&succeeded);
       NS_ENSURE_SUCCESS(rv, rv);
 
       uint32_t requestStatus;
       rv = httpChannel->GetResponseStatus(&requestStatus);
       NS_ENSURE_SUCCESS(rv, rv);
       mozilla::Telemetry::Accumulate(mozilla::Telemetry::URLCLASSIFIER_UPDATE_REMOTE_STATUS2,
                                      mTelemetryProvider, HTTPStatusToBucket(requestStatus));
+      if (requestStatus == 400) {
+        nsCOMPtr<nsIURI> uri;
+        nsAutoCString spec;
+        rv = httpChannel->GetURI(getter_AddRefs(uri));
+        if (NS_SUCCEEDED(rv) && uri) {
+          uri->GetAsciiSpec(spec);
+        }
+        printf_stderr("Safe Browsing server returned a 400 during update: request = %s \n",
+                      spec.get());
+      }
+
       LOG(("nsUrlClassifierStreamUpdater::OnStartRequest %s (%d)", succeeded ?
            "succeeded" : "failed", requestStatus));
       if (!succeeded) {
         // 404 or other error, pass error status back
         strStatus.AppendInt(requestStatus);
         downloadError = true;
       }
     }