- Parse request headers and pass to the scheme handler.
- Fix memory leak in scheme handler implementation.

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@38 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt
2009-08-21 14:21:15 +00:00
parent 087319efdb
commit b821811c08
4 changed files with 53 additions and 25 deletions

View File

@@ -229,28 +229,17 @@ class RequestProxy : public URLRequest::Delegate,
requestimpl->SetURL(UTF8ToWide(params->url.spec())); requestimpl->SetURL(UTF8ToWide(params->url.spec()));
requestimpl->SetMethod(UTF8ToWide(params->method)); requestimpl->SetMethod(UTF8ToWide(params->method));
// Transfer request headers
CefRequest::HeaderMap headerMap; CefRequest::HeaderMap headerMap;
CefRequestImpl::GetHeaderMap(params->headers, headerMap);
// Parse the request header values
std::string headerStr = "HTTP/1.1 200 OK\n";
headerStr += params->headers;
scoped_refptr<net::HttpResponseHeaders> headers =
new HttpResponseHeaders(net::HttpUtil::AssembleRawHeaders(
headerStr.c_str(), headerStr.length()));
void* iter = NULL;
std::string name, value;
while(headers->EnumerateHeaderLines(&iter, &name, &value))
headerMap.insert(std::make_pair(UTF8ToWide(name), UTF8ToWide(value)));
headerMap.insert( headerMap.insert(
std::make_pair(L"Referrer", UTF8ToWide(params->referrer.spec()))); std::make_pair(L"Referrer", UTF8ToWide(params->referrer.spec())));
requestimpl->SetHeaderMap(headerMap); requestimpl->SetHeaderMap(headerMap);
// Transfer post data, if any
scoped_refptr<net::UploadData> upload = params->upload; scoped_refptr<net::UploadData> upload = params->upload;
CefRefPtr<CefPostData> postdata;
if(upload.get()) { if(upload.get()) {
postdata = new CefPostDataImpl(); CefRefPtr<CefPostData> postdata(new CefPostDataImpl());
static_cast<CefPostDataImpl*>(postdata.get())->Set(*upload.get()); static_cast<CefPostDataImpl*>(postdata.get())->Set(*upload.get());
requestimpl->SetPostData(postdata); requestimpl->SetPostData(postdata);
} }

View File

@@ -7,9 +7,14 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/string_util.h" #include "base/string_util.h"
#include "net/http/http_response_headers.h"
#include "net/http/http_util.h"
#include "net/url_request/url_request.h"
#include "webkit/api/public/WebHTTPHeaderVisitor.h" #include "webkit/api/public/WebHTTPHeaderVisitor.h"
#include "webkit/glue/glue_util.h" #include "webkit/glue/glue_util.h"
using net::HttpResponseHeaders;
CefRefPtr<CefRequest> CefRequest::CreateRequest() CefRefPtr<CefRequest> CefRequest::CreateRequest()
{ {
@@ -93,6 +98,27 @@ void CefRequestImpl::Set(const std::wstring& url,
Unlock(); Unlock();
} }
void CefRequestImpl::Set(URLRequest* request)
{
SetURL(UTF8ToWide(request->url().spec()));
SetMethod(UTF8ToWide(request->method()));
// Transfer request headers
HeaderMap headerMap;
GetHeaderMap(request->extra_request_headers(), headerMap);
headerMap.insert(
std::make_pair(L"Referrer", UTF8ToWide(request->referrer())));
SetHeaderMap(headerMap);
// Transfer post data, if any
net::UploadData* data = request->get_upload();
if (data) {
CefRefPtr<CefPostData> postdata(CefPostData::CreatePostData());
static_cast<CefPostDataImpl*>(postdata.get())->Set(*data);
SetPostData(postdata);
}
}
void CefRequestImpl::GetHeaderMap(const WebKit::WebURLRequest& request, void CefRequestImpl::GetHeaderMap(const WebKit::WebURLRequest& request,
HeaderMap& map) HeaderMap& map)
{ {
@@ -127,6 +153,20 @@ void CefRequestImpl::SetHeaderMap(const HeaderMap& map,
} }
} }
void CefRequestImpl::GetHeaderMap(const std::string& header_str, HeaderMap& map)
{
// Parse the request header values
std::string headerStr = "HTTP/1.1 200 OK\n";
headerStr += header_str;
scoped_refptr<net::HttpResponseHeaders> headers =
new HttpResponseHeaders(net::HttpUtil::AssembleRawHeaders(
headerStr.c_str(), headerStr.length()));
void* iter = NULL;
std::string name, value;
while(headers->EnumerateHeaderLines(&iter, &name, &value))
map.insert(std::make_pair(UTF8ToWide(name), UTF8ToWide(value)));
}
CefRefPtr<CefPostData> CefPostData::CreatePostData() CefRefPtr<CefPostData> CefPostData::CreatePostData()
{ {
CefRefPtr<CefPostData> postdata(new CefPostDataImpl()); CefRefPtr<CefPostData> postdata(new CefPostDataImpl());

View File

@@ -10,6 +10,7 @@
#include "webkit/api/public/WebHTTPBody.h" #include "webkit/api/public/WebHTTPBody.h"
#include "webkit/api/public/WebURLRequest.h" #include "webkit/api/public/WebURLRequest.h"
class URLRequest;
// Implementation of CefRequest // Implementation of CefRequest
class CefRequestImpl : public CefThreadSafeBase<CefRequest> class CefRequestImpl : public CefThreadSafeBase<CefRequest>
@@ -31,11 +32,15 @@ public:
CefRefPtr<CefPostData> postData, CefRefPtr<CefPostData> postData,
const HeaderMap& headerMap); const HeaderMap& headerMap);
void Set(URLRequest* request);
static void GetHeaderMap(const WebKit::WebURLRequest& request, static void GetHeaderMap(const WebKit::WebURLRequest& request,
HeaderMap& map); HeaderMap& map);
static void SetHeaderMap(const HeaderMap& map, static void SetHeaderMap(const HeaderMap& map,
WebKit::WebURLRequest& request); WebKit::WebURLRequest& request);
static void GetHeaderMap(const std::string& header_str, HeaderMap& map);
protected: protected:
std::wstring url_; std::wstring url_;
std::wstring method_; std::wstring method_;

View File

@@ -183,16 +183,10 @@ private:
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// safe to perform long operation here // safe to perform long operation here
CefRefPtr<CefRequest> req(CefRequest::CreateRequest()); CefRefPtr<CefRequest> req(CefRequest::CreateRequest());
req->SetURL(UTF8ToWide(url.spec()));
req->SetMethod(UTF8ToWide(owner_->request()->method()));
// check to see if we have post data // populate the request data
net::UploadData* data = owner_->request()->get_upload(); static_cast<CefRequestImpl*>(req.get())->Set(owner_->request());
if (data) {
CefRefPtr<CefPostData> postdata(CefPostData::CreatePostData());
static_cast<CefPostDataImpl*>(postdata.get())->Set(*data);
req->SetPostData(postdata);
}
owner_->handler_->Cancel(); owner_->handler_->Cancel();
std::wstring mime_type; std::wstring mime_type;
int response_length = 0; int response_length = 0;
@@ -386,7 +380,7 @@ public:
} }
void AddRef() {} void AddRef() {}
void Release() {} void Release() { delete this; }
private: private:
CefSchemeHandlerFactory* factory_; CefSchemeHandlerFactory* factory_;