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 // Supply Accept-Encoding field only if it is not already provided. | 401 // TODO(jar): Consider optimizing away SDCH advertising bytes when the URL is |
402 // It should be provided IF the content is known to have restrictions on | 402 // probably an img or such (and SDCH encoding is not likely). |
403 // potential encoding, such as streaming multi-media. | 403 bool advertise_sdch = SdchManager::Global() && |
404 // For details see bug 47381. | 404 SdchManager::Global()->IsInSupportedDomain(request_->url()); |
405 // TODO(jar, enal): jpeg files etc. should set up a request header if | 405 std::string avail_dictionaries; |
406 // possible. Right now it is done only by buffered_resource_loader and | 406 if (advertise_sdch) { |
407 // simple_data_source. | 407 SdchManager::Global()->GetAvailDictionaryList(request_->url(), |
408 if (!request_info_.extra_headers.HasHeader( | 408 &avail_dictionaries); |
409 HttpRequestHeaders::kAcceptEncoding)) { | |
410 bool advertise_sdch = SdchManager::Global() && | |
411 SdchManager::Global()->IsInSupportedDomain(request_->url()); | |
412 std::string avail_dictionaries; | |
413 if (advertise_sdch) { | |
414 SdchManager::Global()->GetAvailDictionaryList(request_->url(), | |
415 &avail_dictionaries); | |
416 | 409 |
417 // The AllowLatencyExperiment() is only true if we've successfully done a | 410 // The AllowLatencyExperiment() is only true if we've successfully done a |
418 // full SDCH compression recently in this browser session for this host. | 411 // full SDCH compression recently in this browser session for this host. |
419 // Note that for this path, there might be no applicable dictionaries, | 412 // Note that for this path, there might be no applicable dictionaries, and |
420 // and hence we can't participate in the experiment. | 413 // hence we can't participate in the experiment. |
421 if (!avail_dictionaries.empty() && | 414 if (!avail_dictionaries.empty() && |
422 SdchManager::Global()->AllowLatencyExperiment(request_->url())) { | 415 SdchManager::Global()->AllowLatencyExperiment(request_->url())) { |
423 // We are participating in the test (or control), and hence we'll | 416 // We are participating in the test (or control), and hence we'll |
424 // eventually record statistics via either SDCH_EXPERIMENT_DECODE or | 417 // eventually record statistics via either SDCH_EXPERIMENT_DECODE or |
425 // SDCH_EXPERIMENT_HOLDBACK, and we'll need some packet timing data. | 418 // SDCH_EXPERIMENT_HOLDBACK, and we'll need some packet timing data. |
426 packet_timing_enabled_ = true; | 419 packet_timing_enabled_ = true; |
427 if (base::RandDouble() < .01) { | 420 if (base::RandDouble() < .01) { |
428 sdch_test_control_ = true; // 1% probability. | 421 sdch_test_control_ = true; // 1% probability. |
429 advertise_sdch = false; | 422 advertise_sdch = false; |
430 } else { | 423 } else { |
431 sdch_test_activated_ = true; | 424 sdch_test_activated_ = true; |
432 } | |
433 } | |
434 } | |
435 | |
436 // Supply Accept-Encoding headers first so that it is more likely that they | |
437 // will be in the first transmitted packet. This can sometimes make it | |
438 // easier to filter and analyze the streams to assure that a proxy has not | |
439 // damaged these headers. Some proxies deliberately corrupt Accept-Encoding | |
440 // headers. | |
441 if (!advertise_sdch) { | |
442 // Tell the server what compression formats we support (other than SDCH). | |
443 request_info_.extra_headers.SetHeader( | |
444 HttpRequestHeaders::kAcceptEncoding, "gzip,deflate"); | |
445 } else { | |
446 // Include SDCH in acceptable list. | |
447 request_info_.extra_headers.SetHeader( | |
448 HttpRequestHeaders::kAcceptEncoding, "gzip,deflate,sdch"); | |
449 if (!avail_dictionaries.empty()) { | |
450 request_info_.extra_headers.SetHeader( | |
451 kAvailDictionaryHeader, | |
452 avail_dictionaries); | |
453 sdch_dictionary_advertised_ = true; | |
454 // Since we're tagging this transaction as advertising a dictionary, | |
455 // we'll definitely employ an SDCH filter (or tentative sdch filter) | |
456 // when we get a response. When done, we'll record histograms via | |
457 // SDCH_DECODE or SDCH_PASSTHROUGH. Hence we need to record packet | |
458 // arrival times. | |
459 packet_timing_enabled_ = true; | |
460 } | 425 } |
461 } | 426 } |
462 } | 427 } |
463 | 428 |
| 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 |
464 URLRequestContext* context = request_->context(); | 454 URLRequestContext* context = request_->context(); |
465 if (context) { | 455 if (context) { |
466 // Only add default Accept-Language and Accept-Charset if the request | 456 // Only add default Accept-Language and Accept-Charset if the request |
467 // didn't have them specified. | 457 // didn't have them specified. |
468 if (!context->accept_language().empty()) { | 458 if (!context->accept_language().empty()) { |
469 request_info_.extra_headers.SetHeaderIfMissing( | 459 request_info_.extra_headers.SetHeaderIfMissing( |
470 HttpRequestHeaders::kAcceptLanguage, | 460 HttpRequestHeaders::kAcceptLanguage, |
471 context->accept_language()); | 461 context->accept_language()); |
472 } | 462 } |
473 if (!context->accept_charset().empty()) { | 463 if (!context->accept_charset().empty()) { |
(...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1419 } | 1409 } |
1420 | 1410 |
1421 bool URLRequestHttpJob::IsCompressibleContent() const { | 1411 bool URLRequestHttpJob::IsCompressibleContent() const { |
1422 std::string mime_type; | 1412 std::string mime_type; |
1423 return GetMimeType(&mime_type) && | 1413 return GetMimeType(&mime_type) && |
1424 (IsSupportedJavascriptMimeType(mime_type.c_str()) || | 1414 (IsSupportedJavascriptMimeType(mime_type.c_str()) || |
1425 IsSupportedNonImageMimeType(mime_type.c_str())); | 1415 IsSupportedNonImageMimeType(mime_type.c_str())); |
1426 } | 1416 } |
1427 | 1417 |
1428 } // namespace net | 1418 } // namespace net |
OLD | NEW |