Chromium Code Reviews

Side by Side 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, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
« no previous file with comments | « no previous file | net/url_request/url_request_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/url_request/url_request_http_job.h" 5 #include "net/url_request/url_request_http_job.h"
6 6
7 #include "base/base_switches.h" 7 #include "base/base_switches.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 569 matching lines...)
580 } else { 580 } else {
581 rv = net::ERR_FAILED; 581 rv = net::ERR_FAILED;
582 } 582 }
583 583
584 // The transaction started synchronously, but we need to notify the 584 // The transaction started synchronously, but we need to notify the
585 // URLRequest delegate via the message loop. 585 // URLRequest delegate via the message loop.
586 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( 586 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
587 this, &URLRequestHttpJob::OnStartCompleted, rv)); 587 this, &URLRequestHttpJob::OnStartCompleted, rv));
588 } 588 }
589 589
590 // Helper. If |*headers| already contains |header_name| do nothing,
591 // otherwise add <header_name> ": " <header_value> to the end of the list.
592 static void AppendHeaderIfMissing(const char* header_name,
593 const std::string& header_value,
594 std::string* headers) {
595 if (header_value.empty())
596 return;
597 if (net::HttpUtil::HasHeader(*headers, header_name))
598 return;
599 *headers += std::string(header_name) + ": " + header_value + "\r\n";
600 }
601
590 void URLRequestHttpJob::AddExtraHeaders() { 602 void URLRequestHttpJob::AddExtraHeaders() {
591 // TODO(jar): Consider optimizing away SDCH advertising bytes when the URL is 603 // TODO(jar): Consider optimizing away SDCH advertising bytes when the URL is
592 // probably an img or such (and SDCH encoding is not likely). 604 // probably an img or such (and SDCH encoding is not likely).
593 bool advertise_sdch = SdchManager::Global() && 605 bool advertise_sdch = SdchManager::Global() &&
594 SdchManager::Global()->IsInSupportedDomain(request_->url()); 606 SdchManager::Global()->IsInSupportedDomain(request_->url());
595 std::string avail_dictionaries; 607 std::string avail_dictionaries;
596 if (advertise_sdch) { 608 if (advertise_sdch) {
597 SdchManager::Global()->GetAvailDictionaryList(request_->url(), 609 SdchManager::Global()->GetAvailDictionaryList(request_->url(),
598 &avail_dictionaries); 610 &avail_dictionaries);
599 611
(...skipping 36 matching lines...)
636 // a response. When done, we'll record histograms via SDCH_DECODE or 648 // a response. When done, we'll record histograms via SDCH_DECODE or
637 // SDCH_PASSTHROUGH. Hence we need to record packet arrival times. 649 // SDCH_PASSTHROUGH. Hence we need to record packet arrival times.
638 EnablePacketCounting(kSdchPacketHistogramCount); 650 EnablePacketCounting(kSdchPacketHistogramCount);
639 } 651 }
640 } 652 }
641 653
642 URLRequestContext* context = request_->context(); 654 URLRequestContext* context = request_->context();
643 if (context) { 655 if (context) {
644 if (context->AllowSendingCookies(request_)) 656 if (context->AllowSendingCookies(request_))
645 request_info_.extra_headers += AssembleRequestCookies(); 657 request_info_.extra_headers += AssembleRequestCookies();
646 if (!context->accept_language().empty()) 658
647 request_info_.extra_headers += "Accept-Language: " + 659 // Only add default Accept-Language and Accept-Charset if the request
648 context->accept_language() + "\r\n"; 660 // didn't have them specifically specified.
eroman 2009/09/24 02:19:32 nit: slightly redundant wording; can probably omit
649 if (!context->accept_charset().empty()) 661 AppendHeaderIfMissing("Accept-Language",
650 request_info_.extra_headers += "Accept-Charset: " + 662 context->accept_language(),
651 context->accept_charset() + "\r\n"; 663 &request_info_.extra_headers);
664 AppendHeaderIfMissing("Accept-Charset",
665 context->accept_charset(),
666 &request_info_.extra_headers);
652 } 667 }
653 } 668 }
654 669
655 std::string URLRequestHttpJob::AssembleRequestCookies() { 670 std::string URLRequestHttpJob::AssembleRequestCookies() {
656 if (request_info_.load_flags & net::LOAD_DO_NOT_SEND_COOKIES) 671 if (request_info_.load_flags & net::LOAD_DO_NOT_SEND_COOKIES)
657 return std::string(); 672 return std::string();
658 673
659 URLRequestContext* context = request_->context(); 674 URLRequestContext* context = request_->context();
660 if (context) { 675 if (context) {
661 // Add in the cookie header. TODO might we need more than one header? 676 // Add in the cookie header. TODO might we need more than one header?
(...skipping 42 matching lines...)
704 719
705 std::string name = "Strict-Transport-Security"; 720 std::string name = "Strict-Transport-Security";
706 std::string value; 721 std::string value;
707 722
708 void* iter = NULL; 723 void* iter = NULL;
709 while (response_info_->headers->EnumerateHeader(&iter, name, &value)) { 724 while (response_info_->headers->EnumerateHeader(&iter, name, &value)) {
710 ctx->strict_transport_security_state()->DidReceiveHeader( 725 ctx->strict_transport_security_state()->DidReceiveHeader(
711 request_info_.url, value); 726 request_info_.url, value);
712 } 727 }
713 } 728 }
OLDNEW
« 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