mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Improve CefURLRequestJob redirect handling (issue #2542)
This commit is contained in:
committed by
Marshall Greenblatt
parent
919ae45b0f
commit
7ea19d740d
@@ -15,6 +15,7 @@
|
||||
#include "libcef/common/response_impl.h"
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "net/base/io_buffer.h"
|
||||
#include "net/base/load_flags.h"
|
||||
#include "net/base/mime_util.h"
|
||||
@@ -27,6 +28,21 @@ using net::URLRequestStatus;
|
||||
|
||||
namespace {
|
||||
|
||||
using HeaderMap = std::multimap<CefString, CefString>;
|
||||
|
||||
struct CaseInsensitiveComparator {
|
||||
base::StringPiece search;
|
||||
CaseInsensitiveComparator(const std::string& s) : search(s) {}
|
||||
bool operator()(const HeaderMap::value_type& p) const {
|
||||
return base::EqualsCaseInsensitiveASCII(search, p.first.ToString());
|
||||
}
|
||||
};
|
||||
|
||||
HeaderMap::const_iterator FindHeader(const HeaderMap& m,
|
||||
const std::string& name) {
|
||||
return std::find_if(m.begin(), m.end(), CaseInsensitiveComparator(name));
|
||||
}
|
||||
|
||||
bool SetHeaderIfMissing(CefRequest::HeaderMap& headerMap,
|
||||
const std::string& name,
|
||||
const std::string& value) {
|
||||
@@ -294,7 +310,7 @@ bool CefResourceRequestJob::IsRedirectResponse(
|
||||
if (redirect_url_.is_valid()) {
|
||||
// Redirect to the new URL.
|
||||
*http_status_code = 303;
|
||||
location->Swap(&redirect_url_);
|
||||
*location = redirect_url_;
|
||||
redirect = true;
|
||||
} else if (response_.get()) {
|
||||
// Check for HTTP 302 or HTTP 303 redirect.
|
||||
@@ -302,17 +318,29 @@ bool CefResourceRequestJob::IsRedirectResponse(
|
||||
if (status == 302 || status == 303) {
|
||||
CefResponse::HeaderMap headerMap;
|
||||
response_->GetHeaderMap(headerMap);
|
||||
CefRequest::HeaderMap::iterator iter = headerMap.find("Location");
|
||||
CefRequest::HeaderMap::const_iterator iter =
|
||||
FindHeader(headerMap, "Location");
|
||||
if (iter != headerMap.end()) {
|
||||
GURL new_url = GURL(std::string(iter->second));
|
||||
*http_status_code = status;
|
||||
location->Swap(&new_url);
|
||||
redirect = true;
|
||||
GURL new_url = request_->url().Resolve(std::string(iter->second));
|
||||
if (new_url.is_valid()) {
|
||||
*http_status_code = status;
|
||||
*location = new_url;
|
||||
redirect = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (redirect) {
|
||||
if (request_->upgrade_if_insecure()) {
|
||||
if (location->SchemeIs("http")) {
|
||||
*insecure_scheme_was_upgraded = true;
|
||||
GURL::Replacements replacements;
|
||||
replacements.SetSchemeStr("https");
|
||||
*location = location->ReplaceComponents(replacements);
|
||||
}
|
||||
}
|
||||
|
||||
// Set the correct response status. This avoids a DCHECK in
|
||||
// RedirectInfo::ComputeRedirectInfo.
|
||||
request_->response_headers()->ReplaceStatusLine(
|
||||
@@ -392,7 +420,7 @@ void CefResourceRequestJob::SendHeaders() {
|
||||
|
||||
if (!redirectUrl.empty()) {
|
||||
std::string redirectUrlStr = redirectUrl;
|
||||
redirect_url_ = GURL(redirectUrlStr);
|
||||
redirect_url_ = request_->url().Resolve(redirectUrlStr);
|
||||
}
|
||||
|
||||
if (remaining_bytes_ > 0)
|
||||
|
Reference in New Issue
Block a user