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:
Marshall Greenblatt 2011-05-26 18:11:56 +00:00
parent 81b0a9a362
commit 42b5597214
4 changed files with 28 additions and 18 deletions

View File

@ -446,14 +446,11 @@ class RequestProxy : public net::URLRequest::Delegate,
CefResponseImpl* responseImpl =
static_cast<CefResponseImpl*>(response.get());
scoped_refptr<net::HttpResponseHeaders> headers(
new net::HttpResponseHeaders(
responseImpl->GenerateResponseLine()));
ResourceResponseInfo info;
info.content_length = static_cast<int64>(offset);
info.mime_type = response->GetMimeType();
info.headers = headers;
info.headers = responseImpl->GetResponseHeaders();
OnReceivedResponse(info, params->url);
AsyncReadData();
} else if (response->GetStatus() != 0) {
@ -462,14 +459,11 @@ class RequestProxy : public net::URLRequest::Delegate,
CefResponseImpl* responseImpl =
static_cast<CefResponseImpl*>(response.get());
scoped_refptr<net::HttpResponseHeaders> headers(
new net::HttpResponseHeaders(
responseImpl->GenerateResponseLine()));
ResourceResponseInfo info;
info.content_length = 0;
info.mime_type = response->GetMimeType();
info.headers = headers;
info.headers = responseImpl->GetResponseHeaders();
OnReceivedResponse(info, params->url);
AsyncReadData();
}

View File

@ -4,10 +4,11 @@
#include "include/cef.h"
#include "response_impl.h"
#include "http_header_utils.h"
#include "base/logging.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/WebURLResponse.h"
@ -92,11 +93,11 @@ void CefResponseImpl::SetHeaderMap(const HeaderMap& headerMap)
header_map_ = headerMap;
}
CefString CefResponseImpl::GenerateResponseLine()
net::HttpResponseHeaders* CefResponseImpl::GetResponseHeaders()
{
AutoLock lock_scope(this);
std::string response_line;
std::string response;
std::string status_text;
if(status_text_.empty())
@ -104,10 +105,24 @@ CefString CefResponseImpl::GenerateResponseLine()
else
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());
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.
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 value;
return new net::HttpResponseHeaders(response);
}

View File

@ -7,6 +7,9 @@
#include "include/cef.h"
namespace net {
class HttpResponseHeaders;
}
namespace WebKit {
class WebURLResponse;
};
@ -30,7 +33,7 @@ public:
virtual void GetHeaderMap(HeaderMap& headerMap);
virtual void SetHeaderMap(const HeaderMap& headerMap);
CefString GenerateResponseLine();
net::HttpResponseHeaders* GetResponseHeaders();
protected:
int status_code_;

View File

@ -123,9 +123,7 @@ public:
virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE {
CefResponseImpl* responseImpl =
static_cast<CefResponseImpl*>(response_.get());
scoped_refptr<net::HttpResponseHeaders> headers(
new net::HttpResponseHeaders(responseImpl->GenerateResponseLine()));
info->headers = headers;
info->headers = responseImpl->GetResponseHeaders();
}
virtual bool IsRedirectResponse(GURL* location, int* http_status_code)