diff --git a/libcef/browser_resource_loader_bridge.cc b/libcef/browser_resource_loader_bridge.cc index 996c70d34..8052d0ebf 100644 --- a/libcef/browser_resource_loader_bridge.cc +++ b/libcef/browser_resource_loader_bridge.cc @@ -446,14 +446,11 @@ class RequestProxy : public net::URLRequest::Delegate, CefResponseImpl* responseImpl = static_cast(response.get()); - scoped_refptr headers( - new net::HttpResponseHeaders( - responseImpl->GenerateResponseLine())); ResourceResponseInfo info; info.content_length = static_cast(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(response.get()); - scoped_refptr 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(); } diff --git a/libcef/response_impl.cc b/libcef/response_impl.cc index 1b9dba434..6a7aac152 100644 --- a/libcef/response_impl.cc +++ b/libcef/response_impl.cc @@ -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); } diff --git a/libcef/response_impl.h b/libcef/response_impl.h index 4d3f64e47..8f83d7b9a 100644 --- a/libcef/response_impl.h +++ b/libcef/response_impl.h @@ -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_; diff --git a/libcef/scheme_impl.cc b/libcef/scheme_impl.cc index abe543eb4..180f79f49 100644 --- a/libcef/scheme_impl.cc +++ b/libcef/scheme_impl.cc @@ -123,9 +123,7 @@ public: virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE { CefResponseImpl* responseImpl = static_cast(response_.get()); - scoped_refptr headers( - new net::HttpResponseHeaders(responseImpl->GenerateResponseLine())); - info->headers = headers; + info->headers = responseImpl->GetResponseHeaders(); } virtual bool IsRedirectResponse(GURL* location, int* http_status_code)