Add support for setting response header values (issue #246).
git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@246 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
parent
81b0a9a362
commit
42b5597214
|
@ -446,14 +446,11 @@ class RequestProxy : public net::URLRequest::Delegate,
|
||||||
|
|
||||||
CefResponseImpl* responseImpl =
|
CefResponseImpl* responseImpl =
|
||||||
static_cast<CefResponseImpl*>(response.get());
|
static_cast<CefResponseImpl*>(response.get());
|
||||||
scoped_refptr<net::HttpResponseHeaders> headers(
|
|
||||||
new net::HttpResponseHeaders(
|
|
||||||
responseImpl->GenerateResponseLine()));
|
|
||||||
|
|
||||||
ResourceResponseInfo info;
|
ResourceResponseInfo info;
|
||||||
info.content_length = static_cast<int64>(offset);
|
info.content_length = static_cast<int64>(offset);
|
||||||
info.mime_type = response->GetMimeType();
|
info.mime_type = response->GetMimeType();
|
||||||
info.headers = headers;
|
info.headers = responseImpl->GetResponseHeaders();
|
||||||
OnReceivedResponse(info, params->url);
|
OnReceivedResponse(info, params->url);
|
||||||
AsyncReadData();
|
AsyncReadData();
|
||||||
} else if (response->GetStatus() != 0) {
|
} else if (response->GetStatus() != 0) {
|
||||||
|
@ -462,14 +459,11 @@ class RequestProxy : public net::URLRequest::Delegate,
|
||||||
|
|
||||||
CefResponseImpl* responseImpl =
|
CefResponseImpl* responseImpl =
|
||||||
static_cast<CefResponseImpl*>(response.get());
|
static_cast<CefResponseImpl*>(response.get());
|
||||||
scoped_refptr<net::HttpResponseHeaders> headers(
|
|
||||||
new net::HttpResponseHeaders(
|
|
||||||
responseImpl->GenerateResponseLine()));
|
|
||||||
|
|
||||||
ResourceResponseInfo info;
|
ResourceResponseInfo info;
|
||||||
info.content_length = 0;
|
info.content_length = 0;
|
||||||
info.mime_type = response->GetMimeType();
|
info.mime_type = response->GetMimeType();
|
||||||
info.headers = headers;
|
info.headers = responseImpl->GetResponseHeaders();
|
||||||
OnReceivedResponse(info, params->url);
|
OnReceivedResponse(info, params->url);
|
||||||
AsyncReadData();
|
AsyncReadData();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,11 @@
|
||||||
|
|
||||||
#include "include/cef.h"
|
#include "include/cef.h"
|
||||||
#include "response_impl.h"
|
#include "response_impl.h"
|
||||||
|
#include "http_header_utils.h"
|
||||||
|
|
||||||
#include "base/logging.h"
|
#include "base/logging.h"
|
||||||
#include "base/stringprintf.h"
|
#include "base/stringprintf.h"
|
||||||
#include "http_header_utils.h"
|
#include "net/http/http_response_headers.h"
|
||||||
#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
|
||||||
#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h"
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h"
|
||||||
|
|
||||||
|
@ -92,11 +93,11 @@ void CefResponseImpl::SetHeaderMap(const HeaderMap& headerMap)
|
||||||
header_map_ = headerMap;
|
header_map_ = headerMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
CefString CefResponseImpl::GenerateResponseLine()
|
net::HttpResponseHeaders* CefResponseImpl::GetResponseHeaders()
|
||||||
{
|
{
|
||||||
AutoLock lock_scope(this);
|
AutoLock lock_scope(this);
|
||||||
|
|
||||||
std::string response_line;
|
std::string response;
|
||||||
std::string status_text;
|
std::string status_text;
|
||||||
|
|
||||||
if(status_text_.empty())
|
if(status_text_.empty())
|
||||||
|
@ -104,10 +105,24 @@ CefString CefResponseImpl::GenerateResponseLine()
|
||||||
else
|
else
|
||||||
status_text = status_text_;
|
status_text = status_text_;
|
||||||
|
|
||||||
base::SStringPrintf(&response_line, "HTTP/1.1 %d %s", status_code_,
|
base::SStringPrintf(&response, "HTTP/1.1 %d %s", status_code_,
|
||||||
status_text.c_str());
|
status_text.c_str());
|
||||||
|
if (header_map_.size() > 0) {
|
||||||
|
for(HeaderMap::const_iterator header = header_map_.begin();
|
||||||
|
header != header_map_.end();
|
||||||
|
++header) {
|
||||||
|
const CefString& key = header->first;
|
||||||
|
const CefString& value = header->second;
|
||||||
|
|
||||||
CefString value(response_line);
|
if(!key.empty()) {
|
||||||
|
// Delimit with "\0" as required by net::HttpResponseHeaders.
|
||||||
return value;
|
std::string key_str(key);
|
||||||
|
std::string value_str(value);
|
||||||
|
base::StringAppendF(&response, "%c%s: %s", '\0', key_str.c_str(),
|
||||||
|
value_str.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new net::HttpResponseHeaders(response);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,9 @@
|
||||||
|
|
||||||
#include "include/cef.h"
|
#include "include/cef.h"
|
||||||
|
|
||||||
|
namespace net {
|
||||||
|
class HttpResponseHeaders;
|
||||||
|
}
|
||||||
namespace WebKit {
|
namespace WebKit {
|
||||||
class WebURLResponse;
|
class WebURLResponse;
|
||||||
};
|
};
|
||||||
|
@ -30,7 +33,7 @@ public:
|
||||||
virtual void GetHeaderMap(HeaderMap& headerMap);
|
virtual void GetHeaderMap(HeaderMap& headerMap);
|
||||||
virtual void SetHeaderMap(const HeaderMap& headerMap);
|
virtual void SetHeaderMap(const HeaderMap& headerMap);
|
||||||
|
|
||||||
CefString GenerateResponseLine();
|
net::HttpResponseHeaders* GetResponseHeaders();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int status_code_;
|
int status_code_;
|
||||||
|
|
|
@ -123,9 +123,7 @@ public:
|
||||||
virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE {
|
virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE {
|
||||||
CefResponseImpl* responseImpl =
|
CefResponseImpl* responseImpl =
|
||||||
static_cast<CefResponseImpl*>(response_.get());
|
static_cast<CefResponseImpl*>(response_.get());
|
||||||
scoped_refptr<net::HttpResponseHeaders> headers(
|
info->headers = responseImpl->GetResponseHeaders();
|
||||||
new net::HttpResponseHeaders(responseImpl->GenerateResponseLine()));
|
|
||||||
info->headers = headers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool IsRedirectResponse(GURL* location, int* http_status_code)
|
virtual bool IsRedirectResponse(GURL* location, int* http_status_code)
|
||||||
|
|
Loading…
Reference in New Issue