From fdc0c904425a152ad425b4278079dcda7ec69ece Mon Sep 17 00:00:00 2001 From: "sfraser%netscape.com" Date: Thu, 17 May 2001 00:17:34 +0000 Subject: [PATCH] Checking in for Gerv. Fix for bug 58040; fix Accept headers to do something useful. r=bbaetz, sr=darin --- modules/libpref/src/init/all.js | 3 +++ netwerk/protocol/http/src/nsHttpHandler.cpp | 22 +++++++++++++++++---- netwerk/protocol/http/src/nsHttpHandler.h | 2 ++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/modules/libpref/src/init/all.js b/modules/libpref/src/init/all.js index 3e67493a0f4..a0b461057eb 100644 --- a/modules/libpref/src/init/all.js +++ b/modules/libpref/src/init/all.js @@ -242,6 +242,9 @@ pref("network.http.keep-alive.max-connections-per-server", 8); pref("network.http.connect.timeout", 30); // in seconds pref("network.http.request.timeout", 120); // in seconds +// Accept header +pref("network.http.accept.default", "text/xml;q=1, text/html;q=0.9, image/png;q=1, image/jpeg;q=1, image/gif;q=0.9, text/plain;q=0.8, text/css;q=1, */*;q=0.01"); + // Enable http compression: comment this out in case of problems with 1.1 pref("network.http.accept-encoding" ,"gzip,deflate,compress,identity"); diff --git a/netwerk/protocol/http/src/nsHttpHandler.cpp b/netwerk/protocol/http/src/nsHttpHandler.cpp index 3dc3deafea9..e6fcdd5f383 100644 --- a/netwerk/protocol/http/src/nsHttpHandler.cpp +++ b/netwerk/protocol/http/src/nsHttpHandler.cpp @@ -23,6 +23,7 @@ * Pierre Phaneuf * Christopher Blizzard * Adrian Havill + * Gervase Markham */ #include "nsHttp.h" @@ -233,11 +234,9 @@ nsHttpHandler::AddStandardRequestHeaders(nsHttpHeaderArray *request, rv = request->SetHeader(nsHttp::User_Agent, UserAgent()); if (NS_FAILED(rv)) return rv; + // MIME based content negotiation lives! // Add the Accept header: - // - // Send */*. We're no longer chopping MIME-types for acceptance. - // MIME based content negotiation has died. - rv = request->SetHeader(nsHttp::Accept, "*/*"); + rv = request->SetHeader(nsHttp::Accept, mAccept.get()); if (NS_FAILED(rv)) return rv; // Add the Accept-Language header: @@ -1056,6 +1055,14 @@ nsHttpHandler::PrefsChanged(const char *pref) } } + if (bChangedAll || PL_strcmp(pref, "network.http.accept.default") == 0) { + nsXPIDLCString accept; + rv = mPrefs->CopyCharPref("network.http.accept.default", + getter_Copies(accept)); + if (NS_SUCCEEDED(rv)) + SetAccept(accept); + } + if (bChangedAll || PL_strcmp(pref, "network.http.accept-encoding") == 0) { nsXPIDLCString acceptEncodings; rv = mPrefs->CopyCharPref("network.http.accept-encoding", @@ -1347,6 +1354,13 @@ nsHttpHandler::SetAcceptCharsets(const char *aAcceptCharsets) return rv; } +nsresult +nsHttpHandler::SetAccept(const char *aAccept) +{ + mAccept = aAccept; + return NS_OK; +} + nsresult nsHttpHandler::SetAcceptEncodings(const char *aAcceptEncodings) { diff --git a/netwerk/protocol/http/src/nsHttpHandler.h b/netwerk/protocol/http/src/nsHttpHandler.h index 4d11ddafdf8..a8151589856 100644 --- a/netwerk/protocol/http/src/nsHttpHandler.h +++ b/netwerk/protocol/http/src/nsHttpHandler.h @@ -170,6 +170,7 @@ private: void InitUserAgentComponents(); void PrefsChanged(const char *pref = nsnull); + nsresult SetAccept(const char *); nsresult SetAcceptLanguages(const char *); nsresult SetAcceptEncodings(const char *); nsresult SetAcceptCharsets(const char *); @@ -211,6 +212,7 @@ private: PRInt32 mMaxIdleConnections; PRInt32 mMaxIdleConnectionsPerServer; + nsCString mAccept; nsCString mAcceptLanguages; nsCString mAcceptEncodings; nsCString mAcceptCharsets;