diff options
author | jungshik@google.com <jungshik@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-23 00:39:47 +0000 |
---|---|---|
committer | jungshik@google.com <jungshik@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-23 00:39:47 +0000 |
commit | fe3d9d77e47bfad0b6984bdd31a1e72b8fc8d2d4 (patch) | |
tree | dbed66e02abd1f8039d8fc05b48a8e18ed73f4b3 /net/http/http_util.cc | |
parent | 7b7d41fc206600571a3352e83a27334ad81775f2 (diff) | |
download | chromium_src-fe3d9d77e47bfad0b6984bdd31a1e72b8fc8d2d4.zip chromium_src-fe3d9d77e47bfad0b6984bdd31a1e72b8fc8d2d4.tar.gz chromium_src-fe3d9d77e47bfad0b6984bdd31a1e72b8fc8d2d4.tar.bz2 |
Add q-values to languages in Accept-Language HTTP header to be compatible with Apache.
Add q-values to charsets in Accept-Charset header in the same way as Firefox does.
BUG=5899
TEST=HttpUtilTest.Accept* (net_unittest)
Review URL: http://codereview.chromium.org/17340
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8527 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_util.cc')
-rw-r--r-- | net/http/http_util.cc | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/net/http/http_util.cc b/net/http/http_util.cc index d69012c..95beb9c 100644 --- a/net/http/http_util.cc +++ b/net/http/http_util.cc @@ -57,7 +57,7 @@ std::string HttpUtil::PathForRequest(const GURL& url) { DCHECK(url.is_valid() && (url.SchemeIs("http") || url.SchemeIs("https"))); if (url.has_query()) return url.path() + "?" + url.query(); - return url.path(); + return url.path(); } // static @@ -430,7 +430,7 @@ std::string HttpUtil::AssembleRawHeaders(const char* input_begin, while (lines.GetNext()) { const char* line_begin = lines.token_begin(); const char* line_end = lines.token_end(); - + if (prev_line_continuable && IsLWS(*line_begin)) { // Join continuation; reduce the leading LWS to a single SP. raw_headers.push_back(' '); @@ -451,6 +451,50 @@ std::string HttpUtil::AssembleRawHeaders(const char* input_begin, return raw_headers; } +// TODO(jungshik): 1. If the list is 'fr-CA,fr-FR,en,de', we have to add +// 'fr' after 'fr-CA' with the same q-value as 'fr-CA' because +// web servers, in general, do not fall back to 'fr' and may end up picking +// 'en' which has a lower preference than 'fr-CA' and 'fr-FR'. +// 2. This function assumes that the input is a comma separated list +// without any whitespace. As long as it comes from the preference and +// a user does not manually edit the preference file, it's the case. Still, +// we may have to make it more robust. +std::string HttpUtil::GenerateAcceptLanguageHeader( + const std::string& raw_language_list) { + // We use integers for qvalue and qvalue decrement that are 10 times + // larger than actual values to avoid a problem with comparing + // two floating point numbers. + const unsigned int kQvalueDecrement10 = 2; + unsigned int qvalue10 = 10; + StringTokenizer t(raw_language_list, ","); + std::string lang_list_with_q; + while (t.GetNext()) { + std::string language = t.token(); + if (qvalue10 == 10) { + // q=1.0 is implicit. + lang_list_with_q = language; + } else { + DCHECK(qvalue10 >= 0 && qvalue10 < 10); + StringAppendF(&lang_list_with_q, ",%s;q=0.%d", language.c_str(), + qvalue10); + } + // It does not make sense to have 'q=0'. + if (qvalue10 > kQvalueDecrement10) + qvalue10 -= kQvalueDecrement10; + } + return lang_list_with_q; +} + +std::string HttpUtil::GenerateAcceptCharsetHeader(const std::string& charset) { + std::string charset_with_q = charset; + if (LowerCaseEqualsASCII(charset, "utf-8")) { + charset_with_q += ",*;q=0.5"; + } else { + charset_with_q += ",utf-8;q=0.7,*;q=0.3"; + } + return charset_with_q; +} + // BNF from section 4.2 of RFC 2616: // // message-header = field-name ":" [ field-value ] |