diff --git a/panda/src/downloader/httpChannel.I b/panda/src/downloader/httpChannel.I index ebb7fe8be3..aeaecb458e 100644 --- a/panda/src/downloader/httpChannel.I +++ b/panda/src/downloader/httpChannel.I @@ -165,6 +165,34 @@ get_redirect() const { return _redirect; } +//////////////////////////////////////////////////////////////////// +// Function: HTTPChannel::get_num_redirect_trail +// Access: Published +// Description: If the document automatically followed one or more +// redirects, this will return the number of redirects +// that were automatically followed. Use +// get_redirect_trail() to retrieve each URL in +// sequence. +//////////////////////////////////////////////////////////////////// +INLINE int HTTPChannel:: +get_num_redirect_trail() const { + return _redirect_trail.size(); +} + +//////////////////////////////////////////////////////////////////// +// Function: HTTPChannel::get_redirect_trail +// Access: Published +// Description: Use in conjunction with get_num_redirect_trail() to +// extract the chain of URL's that the channel was +// automatically redirected through to arrive at the +// final document. +//////////////////////////////////////////////////////////////////// +INLINE const URLSpec &HTTPChannel:: +get_redirect_trail(int n) const { + nassertr(n >= 0 && n < (int)_redirect_trail.size(), _redirect_trail[0]); + return _redirect_trail[n]; +} + //////////////////////////////////////////////////////////////////// // Function: HTTPChannel::set_persistent_connection // Access: Published diff --git a/panda/src/downloader/httpChannel.cxx b/panda/src/downloader/httpChannel.cxx index ff57ef701e..8abdc2e56e 100644 --- a/panda/src/downloader/httpChannel.cxx +++ b/panda/src/downloader/httpChannel.cxx @@ -1738,11 +1738,14 @@ run_reading_header() { _method == HTTPEnum::M_head)) { // Sure! URLSpec new_url = get_redirect(); - if (!_redirect_trail.insert(new_url).second) { + if (find(_redirect_trail.begin(), _redirect_trail.end(), + new_url) != _redirect_trail.end()) { downloader_cat.warning() << "cycle detected in redirect to " << new_url << "\n"; } else { + _redirect_trail.push_back(new_url); + if (downloader_cat.is_debug()) { downloader_cat.debug() << "following redirect to " << new_url << "\n"; diff --git a/panda/src/downloader/httpChannel.h b/panda/src/downloader/httpChannel.h index d1137bc431..40ad46a344 100644 --- a/panda/src/downloader/httpChannel.h +++ b/panda/src/downloader/httpChannel.h @@ -36,6 +36,7 @@ #include "bioPtr.h" #include "bioStreamPtr.h" #include "pmap.h" +#include "pvector.h" #include "pointerTo.h" #include "config_downloader.h" #include "filename.h" @@ -115,6 +116,9 @@ PUBLISHED: INLINE const URLSpec &get_redirect() const; string get_header_value(const string &key) const; + INLINE int get_num_redirect_trail() const; + INLINE const URLSpec &get_redirect_trail(int n) const; + INLINE void set_persistent_connection(bool persistent_connection); INLINE bool get_persistent_connection() const; @@ -394,7 +398,7 @@ private: string _current_field_value; ISocketStream *_body_stream; BIO *_sbio; - pset _redirect_trail; + pvector _redirect_trail; int _last_status_code; double _last_run_time; diff --git a/panda/src/downloader/httpClient.cxx b/panda/src/downloader/httpClient.cxx index 15d4114a0f..2cce61a0ae 100644 --- a/panda/src/downloader/httpClient.cxx +++ b/panda/src/downloader/httpClient.cxx @@ -708,8 +708,8 @@ write_cookies(ostream &out) const { //////////////////////////////////////////////////////////////////// // Function: HTTPClient::send_cookies // Access: Published -// Description: Writes to the indicated ostream a set of Cookie: -// lines for sending the cookies appropriate to the +// Description: Writes to the indicated ostream a "Cookie" header +// line for sending the cookies appropriate to the // indicated URL along with an HTTP request. This also // removes expired cookies. //////////////////////////////////////////////////////////////////// @@ -717,6 +717,7 @@ void HTTPClient:: send_cookies(ostream &out, const URLSpec &url) { HTTPDate now = HTTPDate::now(); bool any_expired = false; + bool first_cookie = true; Cookies::const_iterator ci; for (ci = _cookies.begin(); ci != _cookies.end(); ++ci) { @@ -725,11 +726,20 @@ send_cookies(ostream &out, const URLSpec &url) { any_expired = true; } else if (cookie.matches_url(url)) { - out << "Cookie: " << cookie.get_name() << "=" - << cookie.get_value() << "\r\n"; + if (first_cookie) { + out << "Cookie: "; + first_cookie = false; + } else { + out << "; "; + } + out << cookie.get_name() << "=" << cookie.get_value(); } } + if (!first_cookie) { + out << "\r\n"; + } + if (any_expired) { Cookies new_cookies; Cookies::const_iterator ci;