OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
391 | 391 |
392 // The transaction started synchronously, but we need to notify the | 392 // The transaction started synchronously, but we need to notify the |
393 // URLRequest delegate via the message loop. | 393 // URLRequest delegate via the message loop. |
394 MessageLoop::current()->PostTask( | 394 MessageLoop::current()->PostTask( |
395 FROM_HERE, | 395 FROM_HERE, |
396 method_factory_.NewRunnableMethod( | 396 method_factory_.NewRunnableMethod( |
397 &URLRequestHttpJob::OnStartCompleted, rv)); | 397 &URLRequestHttpJob::OnStartCompleted, rv)); |
398 } | 398 } |
399 | 399 |
400 void URLRequestHttpJob::AddExtraHeaders() { | 400 void URLRequestHttpJob::AddExtraHeaders() { |
401 // TODO(jar): Consider optimizing away SDCH advertising bytes when the URL is | 401 // Supply Accept-Encoding field only if it is not already supplied. |
402 // probably an img or such (and SDCH encoding is not likely). | 402 if (!request_info_.extra_headers.HasHeader( |
403 bool advertise_sdch = SdchManager::Global() && | 403 HttpRequestHeaders::kAcceptEncoding)) { |
404 SdchManager::Global()->IsInSupportedDomain(request_->url()); | 404 // TODO(jar): Consider optimizing away SDCH advertising bytes when the URL |
405 std::string avail_dictionaries; | 405 // is probably an img or such (and SDCH encoding is not likely). |
jar (doing other things)
2011/06/09 21:24:37
Do you think this Todo() is satisfied? Perhaps it
enal
2011/06/09 21:55:03
Done.
| |
406 if (advertise_sdch) { | 406 bool advertise_sdch = SdchManager::Global() && |
407 SdchManager::Global()->GetAvailDictionaryList(request_->url(), | 407 SdchManager::Global()->IsInSupportedDomain(request_->url()); |
408 &avail_dictionaries); | 408 std::string avail_dictionaries; |
409 if (advertise_sdch) { | |
410 SdchManager::Global()->GetAvailDictionaryList(request_->url(), | |
411 &avail_dictionaries); | |
409 | 412 |
410 // The AllowLatencyExperiment() is only true if we've successfully done a | 413 // The AllowLatencyExperiment() is only true if we've successfully done a |
411 // full SDCH compression recently in this browser session for this host. | 414 // full SDCH compression recently in this browser session for this host. |
412 // Note that for this path, there might be no applicable dictionaries, and | 415 // Note that for this path, there might be no applicable dictionaries, |
413 // hence we can't participate in the experiment. | 416 // and hence we can't participate in the experiment. |
414 if (!avail_dictionaries.empty() && | 417 if (!avail_dictionaries.empty() && |
415 SdchManager::Global()->AllowLatencyExperiment(request_->url())) { | 418 SdchManager::Global()->AllowLatencyExperiment(request_->url())) { |
416 // We are participating in the test (or control), and hence we'll | 419 // We are participating in the test (or control), and hence we'll |
417 // eventually record statistics via either SDCH_EXPERIMENT_DECODE or | 420 // eventually record statistics via either SDCH_EXPERIMENT_DECODE or |
418 // SDCH_EXPERIMENT_HOLDBACK, and we'll need some packet timing data. | 421 // SDCH_EXPERIMENT_HOLDBACK, and we'll need some packet timing data. |
419 packet_timing_enabled_ = true; | 422 packet_timing_enabled_ = true; |
420 if (base::RandDouble() < .01) { | 423 if (base::RandDouble() < .01) { |
421 sdch_test_control_ = true; // 1% probability. | 424 sdch_test_control_ = true; // 1% probability. |
422 advertise_sdch = false; | 425 advertise_sdch = false; |
423 } else { | 426 } else { |
424 sdch_test_activated_ = true; | 427 sdch_test_activated_ = true; |
428 } | |
429 } | |
430 } | |
431 | |
432 // Supply Accept-Encoding headers first so that it is more likely that they | |
433 // will be in the first transmitted packet. This can sometimes make it | |
434 // easier to filter and analyze the streams to assure that a proxy has not | |
435 // damaged these headers. Some proxies deliberately corrupt Accept-Encoding | |
436 // headers. | |
437 if (!advertise_sdch) { | |
438 // Tell the server what compression formats we support (other than SDCH). | |
439 request_info_.extra_headers.SetHeader( | |
440 HttpRequestHeaders::kAcceptEncoding, "gzip,deflate"); | |
441 } else { | |
442 // Include SDCH in acceptable list. | |
443 request_info_.extra_headers.SetHeader( | |
444 HttpRequestHeaders::kAcceptEncoding, "gzip,deflate,sdch"); | |
445 if (!avail_dictionaries.empty()) { | |
446 request_info_.extra_headers.SetHeader( | |
447 kAvailDictionaryHeader, | |
448 avail_dictionaries); | |
449 sdch_dictionary_advertised_ = true; | |
450 // Since we're tagging this transaction as advertising a dictionary, | |
451 // we'll definitely employ an SDCH filter (or tentative sdch filter) | |
452 // when we get a response. When done, we'll record histograms via | |
453 // SDCH_DECODE or SDCH_PASSTHROUGH. Hence we need to record packet | |
454 // arrival times. | |
455 packet_timing_enabled_ = true; | |
425 } | 456 } |
426 } | 457 } |
427 } | 458 } |
428 | 459 |
429 // Supply Accept-Encoding headers first so that it is more likely that they | |
430 // will be in the first transmitted packet. This can sometimes make it easier | |
431 // to filter and analyze the streams to assure that a proxy has not damaged | |
432 // these headers. Some proxies deliberately corrupt Accept-Encoding headers. | |
433 if (!advertise_sdch) { | |
434 // Tell the server what compression formats we support (other than SDCH). | |
435 request_info_.extra_headers.SetHeader( | |
436 HttpRequestHeaders::kAcceptEncoding, "gzip,deflate"); | |
437 } else { | |
438 // Include SDCH in acceptable list. | |
439 request_info_.extra_headers.SetHeader( | |
440 HttpRequestHeaders::kAcceptEncoding, "gzip,deflate,sdch"); | |
441 if (!avail_dictionaries.empty()) { | |
442 request_info_.extra_headers.SetHeader( | |
443 kAvailDictionaryHeader, | |
444 avail_dictionaries); | |
445 sdch_dictionary_advertised_ = true; | |
446 // Since we're tagging this transaction as advertising a dictionary, we'll | |
447 // definitely employ an SDCH filter (or tentative sdch filter) when we get | |
448 // a response. When done, we'll record histograms via SDCH_DECODE or | |
449 // SDCH_PASSTHROUGH. Hence we need to record packet arrival times. | |
450 packet_timing_enabled_ = true; | |
451 } | |
452 } | |
453 | |
454 URLRequestContext* context = request_->context(); | 460 URLRequestContext* context = request_->context(); |
455 if (context) { | 461 if (context) { |
456 // Only add default Accept-Language and Accept-Charset if the request | 462 // Only add default Accept-Language and Accept-Charset if the request |
457 // didn't have them specified. | 463 // didn't have them specified. |
458 if (!context->accept_language().empty()) { | 464 if (!context->accept_language().empty()) { |
459 request_info_.extra_headers.SetHeaderIfMissing( | 465 request_info_.extra_headers.SetHeaderIfMissing( |
460 HttpRequestHeaders::kAcceptLanguage, | 466 HttpRequestHeaders::kAcceptLanguage, |
461 context->accept_language()); | 467 context->accept_language()); |
462 } | 468 } |
463 if (!context->accept_charset().empty()) { | 469 if (!context->accept_charset().empty()) { |
(...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1409 } | 1415 } |
1410 | 1416 |
1411 bool URLRequestHttpJob::IsCompressibleContent() const { | 1417 bool URLRequestHttpJob::IsCompressibleContent() const { |
1412 std::string mime_type; | 1418 std::string mime_type; |
1413 return GetMimeType(&mime_type) && | 1419 return GetMimeType(&mime_type) && |
1414 (IsSupportedJavascriptMimeType(mime_type.c_str()) || | 1420 (IsSupportedJavascriptMimeType(mime_type.c_str()) || |
1415 IsSupportedNonImageMimeType(mime_type.c_str())); | 1421 IsSupportedNonImageMimeType(mime_type.c_str())); |
1416 } | 1422 } |
1417 | 1423 |
1418 } // namespace net | 1424 } // namespace net |
OLD | NEW |