From 8fa43a4630dde5eb71b75ec0b917278ee6d2554a Mon Sep 17 00:00:00 2001 From: Doug Turner Date: Sun, 13 Apr 2014 21:39:13 -0700 Subject: [PATCH] Bug 995070 - Add preference to send 'Prefer: Safe' header as defined by draft-nottingham-safe-hint-01. r=mcmanus --- netwerk/protocol/http/nsHttpAtomList.h | 1 + netwerk/protocol/http/nsHttpHandler.cpp | 17 +++++++++++++++++ netwerk/protocol/http/nsHttpHandler.h | 3 +++ 3 files changed, 21 insertions(+) diff --git a/netwerk/protocol/http/nsHttpAtomList.h b/netwerk/protocol/http/nsHttpAtomList.h index ac10a4e297b9..81c4528a4e52 100644 --- a/netwerk/protocol/http/nsHttpAtomList.h +++ b/netwerk/protocol/http/nsHttpAtomList.h @@ -62,6 +62,7 @@ HTTP_ATOM(Location, "Location") HTTP_ATOM(Max_Forwards, "Max-Forwards") HTTP_ATOM(Overwrite, "Overwrite") HTTP_ATOM(Pragma, "Pragma") +HTTP_ATOM(Prefer, "Prefer") HTTP_ATOM(Proxy_Authenticate, "Proxy-Authenticate") HTTP_ATOM(Proxy_Authorization, "Proxy-Authorization") HTTP_ATOM(Proxy_Connection, "Proxy-Connection") diff --git a/netwerk/protocol/http/nsHttpHandler.cpp b/netwerk/protocol/http/nsHttpHandler.cpp index dffed5173ce8..e683ba58b166 100644 --- a/netwerk/protocol/http/nsHttpHandler.cpp +++ b/netwerk/protocol/http/nsHttpHandler.cpp @@ -86,6 +86,7 @@ extern PRThread *gSocketThread; #define DONOTTRACK_VALUE_UNSET 2 #define TELEMETRY_ENABLED "toolkit.telemetry.enabled" #define ALLOW_EXPERIMENTS "network.allow-experiments" +#define SAFE_HINT_HEADER_VALUE "safeHint.enabled" #define UA_PREF(_pref) UA_PREF_PREFIX _pref #define HTTP_PREF(_pref) HTTP_PREF_PREFIX _pref @@ -172,6 +173,7 @@ nsHttpHandler::nsHttpHandler() , mEnablePersistentHttpsCaching(false) , mDoNotTrackEnabled(false) , mDoNotTrackValue(1) + , mSafeHintEnabled(false) , mTelemetryEnabled(false) , mAllowExperiments(true) , mHandlerActive(false) @@ -270,6 +272,7 @@ nsHttpHandler::Init() prefBranch->AddObserver(TELEMETRY_ENABLED, this, true); prefBranch->AddObserver(HTTP_PREF("tcp_keepalive.short_lived_connections"), this, true); prefBranch->AddObserver(HTTP_PREF("tcp_keepalive.long_lived_connections"), this, true); + prefBranch->AddObserver(SAFE_HINT_HEADER_VALUE, this, true); PrefsChanged(prefBranch, nullptr); } @@ -417,6 +420,11 @@ nsHttpHandler::AddStandardRequestHeaders(nsHttpHeaderArray *request) if (NS_FAILED(rv)) return rv; } + // add the "Send Hint" header + if (mSafeHintEnabled) { + rv = request->SetHeader(nsHttp::Prefer, NS_LITERAL_CSTRING("safe")); + if (NS_FAILED(rv)) return rv; + } return NS_OK; } @@ -1293,6 +1301,15 @@ nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref) } } + // Hint option + if (PREF_CHANGED(SAFE_HINT_HEADER_VALUE)) { + cVar = false; + rv = prefs->GetBoolPref(SAFE_HINT_HEADER_VALUE, &cVar); + if (NS_SUCCEEDED(rv)) { + mSafeHintEnabled = cVar; + } + } + // toggle to true anytime a token bucket related pref is changed.. that // includes telemetry and allow-experiments because of the abtest profile bool requestTokenBucketUpdated = false; diff --git a/netwerk/protocol/http/nsHttpHandler.h b/netwerk/protocol/http/nsHttpHandler.h index 4586b9e8a1ca..9ec639350112 100644 --- a/netwerk/protocol/http/nsHttpHandler.h +++ b/netwerk/protocol/http/nsHttpHandler.h @@ -434,6 +434,9 @@ private: bool mDoNotTrackEnabled; uint8_t mDoNotTrackValue; + // for broadcasting safe hint; + bool mSafeHintEnabled; + // Whether telemetry is reported or not uint32_t mTelemetryEnabled : 1;