Bug 1619584 - Allow TRR to append DNS query string r=valentin
authorKershaw Chang <kershaw@mozilla.com>
Wed, 18 Mar 2020 15:12:52 +0000
changeset 519383 52cfa33cd009a95556ad3cbbdf0ab28b4452771b
parent 519382 b2610da590776d9b805618fcaf46a66b37fb1475
child 519384 400e2c6564c5a4186a3da9c2e76fdf71c7a5f3c7
push id37227
push userapavel@mozilla.com
push dateThu, 19 Mar 2020 03:53:34 +0000
treeherdermozilla-central@c63d5667aa2c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1619584
milestone76.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1619584 - Allow TRR to append DNS query string r=valentin Depends on D66772 Differential Revision: https://phabricator.services.mozilla.com/D67150
netwerk/dns/TRR.cpp
--- a/netwerk/dns/TRR.cpp
+++ b/netwerk/dns/TRR.cpp
@@ -12,16 +12,17 @@
 #include "nsIHttpChannel.h"
 #include "nsIHttpChannelInternal.h"
 #include "nsIIOService.h"
 #include "nsIInputStream.h"
 #include "nsISupportsBase.h"
 #include "nsISupportsUtils.h"
 #include "nsITimedChannel.h"
 #include "nsIUploadChannel2.h"
+#include "nsIURIMutator.h"
 #include "nsNetUtil.h"
 #include "nsStringStream.h"
 #include "nsThreadUtils.h"
 #include "nsURLHelper.h"
 #include "TRR.h"
 #include "TRRService.h"
 
 #include "mozilla/Base64.h"
@@ -278,20 +279,38 @@ nsresult TRR::SendHTTPRequest() {
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsAutoCString uri;
     if (UseDefaultServer()) {
       gTRRService->GetURI(uri);
     } else {
       uri = mRec->mTrrServer;
     }
-    uri.Append(NS_LITERAL_CSTRING("?dns="));
-    uri.Append(body);
+
+    rv = NS_NewURI(getter_AddRefs(dnsURI), uri);
+    if (NS_FAILED(rv)) {
+      LOG(("TRR:SendHTTPRequest: NewURI failed!\n"));
+      return rv;
+    }
+
+    nsAutoCString query;
+    rv = dnsURI->GetQuery(query);
+    if (NS_FAILED(rv)) {
+      return rv;
+    }
+
+    if (query.IsEmpty()) {
+      query.Assign(NS_LITERAL_CSTRING("?dns="));
+  } else {
+      query.Append(NS_LITERAL_CSTRING("&dns="));
+    }
+    query.Append(body);
+
+    rv = NS_MutateURI(dnsURI).SetQuery(query).Finalize(dnsURI);
     LOG(("TRR::SendHTTPRequest GET dns=%s\n", body.get()));
-    rv = NS_NewURI(getter_AddRefs(dnsURI), uri);
   } else {
     rv = DohEncode(body, disableECS);
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsAutoCString uri;
     if (UseDefaultServer()) {
       gTRRService->GetURI(uri);
     } else {