Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Unified Diff: net/url_request/url_request_http_job.cc

Issue 218015: Don't add default Accept-Language and Accept-Charset headers if specific ones... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/url_request/url_request_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/url_request/url_request_http_job.cc
===================================================================
--- net/url_request/url_request_http_job.cc (revision 26884)
+++ net/url_request/url_request_http_job.cc (working copy)
@@ -587,6 +587,18 @@
this, &URLRequestHttpJob::OnStartCompleted, rv));
}
+// Helper. If |*headers| already contains |header_name| do nothing,
+// otherwise add <header_name> ": " <header_value> to the end of the list.
+static void AppendHeaderIfMissing(const char* header_name,
+ const std::string& header_value,
+ std::string* headers) {
+ if (header_value.empty())
+ return;
+ if (net::HttpUtil::HasHeader(*headers, header_name))
+ return;
+ *headers += std::string(header_name) + ": " + header_value + "\r\n";
+}
+
void URLRequestHttpJob::AddExtraHeaders() {
// TODO(jar): Consider optimizing away SDCH advertising bytes when the URL is
// probably an img or such (and SDCH encoding is not likely).
@@ -643,12 +655,15 @@
if (context) {
if (context->AllowSendingCookies(request_))
request_info_.extra_headers += AssembleRequestCookies();
- if (!context->accept_language().empty())
- request_info_.extra_headers += "Accept-Language: " +
- context->accept_language() + "\r\n";
- if (!context->accept_charset().empty())
- request_info_.extra_headers += "Accept-Charset: " +
- context->accept_charset() + "\r\n";
+
+ // Only add default Accept-Language and Accept-Charset if the request
+ // didn't have them specifically specified.
eroman 2009/09/24 02:19:32 nit: slightly redundant wording; can probably omit
+ AppendHeaderIfMissing("Accept-Language",
+ context->accept_language(),
+ &request_info_.extra_headers);
+ AppendHeaderIfMissing("Accept-Charset",
+ context->accept_charset(),
+ &request_info_.extra_headers);
}
}
« no previous file with comments | « no previous file | net/url_request/url_request_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698