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

Unified Diff: libcurl_http_fetcher.cc

Issue 5205002: AU: Manual proxy support (Closed) Base URL: http://git.chromium.org/git/update_engine.git@master
Patch Set: Created 10 years, 1 month 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
Index: libcurl_http_fetcher.cc
diff --git a/libcurl_http_fetcher.cc b/libcurl_http_fetcher.cc
index 460b980c5bd87521e13c10f151d7b8a5ebf42dd0..909bd6bef07115dbf5fdb17900f9392f5d15feef 100644
--- a/libcurl_http_fetcher.cc
+++ b/libcurl_http_fetcher.cc
@@ -9,6 +9,7 @@
#include <base/logging.h>
+#include "update_engine/chrome_proxy_resolver.h"
#include "update_engine/dbus_interface.h"
#include "update_engine/flimflam_proxy.h"
#include "update_engine/utils.h"
@@ -59,6 +60,29 @@ void LibcurlHttpFetcher::ResumeTransfer(const std::string& url) {
curl_handle_ = curl_easy_init();
CHECK(curl_handle_);
+ if (!HasProxy()) {
+ LOG(ERROR) << "Missing proxy.";
petkov 2010/11/19 05:37:15 This is a really unexpected case, right? If you en
adlr 2010/11/20 02:52:29 good call. changed to CHECK
+ } else {
+ LOG(INFO) << "Using proxy: " << CurrentProxy();
+ if (CurrentProxy() == kNoProxy) {
+ CHECK_EQ(curl_easy_setopt(curl_handle_,
+ CURLOPT_PROXY,
+ ""), CURLE_OK);
+ } else {
+ CHECK_EQ(curl_easy_setopt(curl_handle_,
+ CURLOPT_PROXY,
+ CurrentProxy().c_str()), CURLE_OK);
+ // Curl seems to require us to set the protocol
+ curl_proxytype type;
+ if (ChromeProxyResolver::GetProxyType(CurrentProxy(), &type)) {
+ LOG(INFO) << "Set proxtype to: " << type;
petkov 2010/11/19 05:37:15 Set proxy type?
adlr 2010/11/20 02:52:29 removed this line; was kinda redundant
+ CHECK_EQ(curl_easy_setopt(curl_handle_,
+ CURLOPT_PROXYTYPE,
+ type), CURLE_OK);
+ }
+ }
+ }
+
if (post_data_set_) {
CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_POST, 1), CURLE_OK);
CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_POSTFIELDS,
@@ -133,6 +157,7 @@ void LibcurlHttpFetcher::BeginTransfer(const std::string& url) {
resume_offset_ = 0;
retry_count_ = 0;
http_response_code_ = 0;
+ ResolveProxiesForUrl(url);
ResumeTransfer(url);
CurlPerformOnce();
}
@@ -178,6 +203,26 @@ void LibcurlHttpFetcher::CurlPerformOnce() {
// we're done!
CleanUp();
+ if (!sent_byte_ &&
+ (http_response_code_ < 200 || http_response_code_ >= 300)) {
+ // The transfer completed w/ error and we didn't get any bytes.
+ // If we have another proxy to try, try that.
+
+ PopProxy(); // Delete the proxy we just gave up on.
+
+ if (HasProxy()) {
+ // We have another proxy. Retry immediately.
+ g_timeout_add_seconds(0,
petkov 2010/11/19 05:37:15 g_idle_add?
adlr 2010/11/20 02:52:29 Done.
+ &LibcurlHttpFetcher::StaticRetryTimeoutCallback,
+ this);
+ } else {
+ // Out of proxies. Give up.
+ if (delegate_)
+ delegate_->TransferComplete(this, false); // success
+ }
+ return;
+ }
+
if ((transfer_size_ >= 0) && (bytes_downloaded_ < transfer_size_)) {
// Need to restart transfer
retry_count_++;
@@ -208,6 +253,7 @@ void LibcurlHttpFetcher::CurlPerformOnce() {
}
size_t LibcurlHttpFetcher::LibcurlWrite(void *ptr, size_t size, size_t nmemb) {
+ sent_byte_ = true;
petkov 2010/11/19 05:37:15 are you sure size > 0?
adlr 2010/11/20 02:52:29 hadn't considered that. Should we even call anyone
GetHttpResponseCode();
{
double transfer_size_double;

Powered by Google App Engine
This is Rietveld 408576698