Author: ruschein
Date: 2011-09-21 16:28:34 -0700 (Wed, 21 Sep 2011)
New Revision: 26918
Modified:
csplugins/trunk/ucsd/ruschein/GSFS/include/Downloader.h
csplugins/trunk/ucsd/ruschein/GSFS/src/Downloader.cc
Log:
Added debugging output to trace the HTTP requests, also added the capability to
add arbitrary HTTP headers.
Modified: csplugins/trunk/ucsd/ruschein/GSFS/include/Downloader.h
===================================================================
--- csplugins/trunk/ucsd/ruschein/GSFS/include/Downloader.h 2011-09-21
23:05:48 UTC (rev 26917)
+++ csplugins/trunk/ucsd/ruschein/GSFS/include/Downloader.h 2011-09-21
23:28:34 UTC (rev 26918)
@@ -35,6 +35,7 @@
#include <HttpHeader.h>
#include <RobotsDotTxt.h>
#include <PerlCompatRegExp.h>
+#include <SList.h>
#include <ThreadUtil.h>
#include <Url.h>
@@ -57,6 +58,7 @@
static ThreadUtil::Mutex *cookie_mutex_;
static ThreadUtil::Mutex *robots_dot_txt_mutex_;
static GNU_HASH_MAP<std::string, RobotsDotTxt>
url_to_robots_dot_txt_map_;
+ static bool debug_;
protected:
bool multi_mode_;
public:
@@ -109,6 +111,8 @@
typedef int (*DebugFunc)(CURL *handle, curl_infotype infotype, char
*data, size_t size, void *this_pointer);
public:
explicit Downloader(const Params ¶ms = Params()):
multi_mode_(false), additional_http_headers_(NULL), params_(params) { init(); }
+ explicit Downloader(const Url &url, const SList<std::string>
&additional_http_headers, const Params ¶ms = Params(),
+ const TimeLimit &time_limit = DEFAULT_TIME_LIMIT);
explicit Downloader(const Url &url, const Params ¶ms = Params(),
const TimeLimit &time_limit = DEFAULT_TIME_LIMIT);
explicit Downloader(const std::string &url, const Params ¶ms =
Params(), const TimeLimit &time_limit = DEFAULT_TIME_LIMIT, bool multimode =
false);
virtual ~Downloader();
@@ -147,13 +151,14 @@
static const std::string &GetDefaultUserAgentString();
+ /** Turn debug output on stderr or or off. */
+ static void setDebugMode(const bool on) { Downloader::debug_ = on; }
protected:
void setMultiMode(const bool multi) { multi_mode_ = multi; }
bool getMultiMode() const { return multi_mode_ ; }
CURL *getEasyHandle() const { return easy_handle_; }
-
private:
static void InitCurlEasyHandle(const long dns_cache_timeout, const char
* const error_buffer, const bool debugging,
WriteFunc write_func, LockFunc
lock_func, UnlockFunc unlock_func, HeaderFunc header_func, DebugFunc debug_func,
Modified: csplugins/trunk/ucsd/ruschein/GSFS/src/Downloader.cc
===================================================================
--- csplugins/trunk/ucsd/ruschein/GSFS/src/Downloader.cc 2011-09-21
23:05:48 UTC (rev 26917)
+++ csplugins/trunk/ucsd/ruschein/GSFS/src/Downloader.cc 2011-09-21
23:28:34 UTC (rev 26918)
@@ -61,6 +61,7 @@
const std::string Downloader::DEFAULT_ACCEPTABLE_LANGUAGES("en,eng,english");
std::string Downloader::DENIED_BY_ROBOTS_DOT_TXT_ERROR_MSG("Disallowed by
robots.txt.");
std::string Downloader::default_user_agent_string_;
+bool Downloader::debug_(false);
Downloader::Params::Params(const std::string &user_agent, const std::string
&acceptable_languages, const long max_redirect_count,
@@ -78,20 +79,33 @@
}
-Downloader::Downloader(const Url &url, const Params ¶ms, const TimeLimit
&time_limit): multi_mode_(false), additional_http_headers_(NULL),
params_(params)
+Downloader::Downloader(const Url &url, const Params ¶ms, const TimeLimit
&time_limit)
+ : multi_mode_(false), additional_http_headers_(NULL), params_(params)
{
init();
newUrl(url, time_limit);
}
-Downloader::Downloader(const std::string &url, const Params ¶ms, const
TimeLimit &time_limit, bool multimode): multi_mode_(multimode),
additional_http_headers_(NULL), params_(params)
+Downloader::Downloader(const Url &url, const SList<std::string>
&additional_http_headers, const Params ¶ms,
+ const TimeLimit &time_limit): multi_mode_(false),
additional_http_headers_(NULL), params_(params)
{
+ for (SList<std::string>::const_iterator header =
additional_http_headers.begin(); header != additional_http_headers.end();
+ ++header)
+ additional_http_headers_ =
curl_slist_append(additional_http_headers_, header->c_str());
init();
newUrl(url, time_limit);
}
+Downloader::Downloader(const std::string &url, const Params ¶ms, const
TimeLimit &time_limit, bool multimode)
+ : multi_mode_(multimode), additional_http_headers_(NULL),
params_(params)
+{
+ init();
+ newUrl(url, time_limit);
+}
+
+
Downloader::~Downloader()
{
--instance_count_;
@@ -143,6 +157,9 @@
header_.clear();
body_.clear();
+ // Turn debug output on stderr or or off:
+ ::curl_easy_setopt(easy_handle_, CURLOPT_VERBOSE, debug_ ? 1 : 0);
+
for (;;) {
// Too many redirects?
if (getRemainingNoOfRedirects() < 1) {
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.