redirect_trail, cookie fixes

This commit is contained in:
David Rose 2004-08-28 01:10:25 +00:00
parent 9a748b971f
commit 5a2277ca6b
4 changed files with 51 additions and 6 deletions

View File

@ -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

View File

@ -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";

View File

@ -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<URLSpec> _redirect_trail;
pvector<URLSpec> _redirect_trail;
int _last_status_code;
double _last_run_time;

View File

@ -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;