2010-10-03 23:04:50 +02:00
|
|
|
// Copyright (c) 2010 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "string_util.h"
|
2011-12-23 18:36:30 +01:00
|
|
|
#include "include/cef_request.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include <sstream>
|
|
|
|
|
2010-11-22 18:49:46 +01:00
|
|
|
void DumpRequestContents(CefRefPtr<CefRequest> request, std::string& str)
|
2010-10-03 23:04:50 +02:00
|
|
|
{
|
2010-11-22 18:49:46 +01:00
|
|
|
std::stringstream ss;
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2010-11-22 18:49:46 +01:00
|
|
|
ss << "URL: " << std::string(request->GetURL());
|
|
|
|
ss << "\nMethod: " << std::string(request->GetMethod());
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
CefRequest::HeaderMap headerMap;
|
|
|
|
request->GetHeaderMap(headerMap);
|
|
|
|
if(headerMap.size() > 0) {
|
2010-11-22 18:49:46 +01:00
|
|
|
ss << "\nHeaders:";
|
2010-10-03 23:04:50 +02:00
|
|
|
CefRequest::HeaderMap::const_iterator it = headerMap.begin();
|
|
|
|
for(; it != headerMap.end(); ++it) {
|
2010-11-22 18:49:46 +01:00
|
|
|
ss << "\n\t" << std::string((*it).first) << ": " <<
|
|
|
|
std::string((*it).second);
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefPostData> postData = request->GetPostData();
|
|
|
|
if(postData.get()) {
|
|
|
|
CefPostData::ElementVector elements;
|
|
|
|
postData->GetElements(elements);
|
|
|
|
if(elements.size() > 0) {
|
2010-11-22 18:49:46 +01:00
|
|
|
ss << "\nPost Data:";
|
2010-10-03 23:04:50 +02:00
|
|
|
CefRefPtr<CefPostDataElement> element;
|
|
|
|
CefPostData::ElementVector::const_iterator it = elements.begin();
|
|
|
|
for(; it != elements.end(); ++it) {
|
|
|
|
element = (*it);
|
|
|
|
if(element->GetType() == PDE_TYPE_BYTES) {
|
|
|
|
// the element is composed of bytes
|
2010-11-22 18:49:46 +01:00
|
|
|
ss << "\n\tBytes: ";
|
2010-10-03 23:04:50 +02:00
|
|
|
if(element->GetBytesCount() == 0)
|
2010-11-22 18:49:46 +01:00
|
|
|
ss << "(empty)";
|
2010-10-03 23:04:50 +02:00
|
|
|
else {
|
|
|
|
// retrieve the data.
|
|
|
|
size_t size = element->GetBytesCount();
|
|
|
|
char* bytes = new char[size];
|
|
|
|
element->GetBytes(size, bytes);
|
2010-11-22 18:49:46 +01:00
|
|
|
ss << std::string(bytes, size);
|
2010-10-03 23:04:50 +02:00
|
|
|
delete [] bytes;
|
|
|
|
}
|
|
|
|
} else if(element->GetType() == PDE_TYPE_FILE) {
|
2010-11-22 18:49:46 +01:00
|
|
|
ss << "\n\tFile: " << std::string(element->GetFile());
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
str = ss.str();
|
|
|
|
}
|
|
|
|
|
2010-11-22 18:49:46 +01:00
|
|
|
std::string StringReplace(const std::string& str, const std::string& from,
|
|
|
|
const std::string& to)
|
2010-10-03 23:04:50 +02:00
|
|
|
{
|
2010-11-22 18:49:46 +01:00
|
|
|
std::string result = str;
|
|
|
|
std::string::size_type pos = 0;
|
|
|
|
std::string::size_type from_len = from.length();
|
|
|
|
std::string::size_type to_len = to.length();
|
2010-10-03 23:04:50 +02:00
|
|
|
do {
|
|
|
|
pos = result.find(from, pos);
|
2010-11-22 18:49:46 +01:00
|
|
|
if(pos != std::string::npos) {
|
2010-10-03 23:04:50 +02:00
|
|
|
result.replace(pos, from_len, to);
|
|
|
|
pos += to_len;
|
|
|
|
}
|
2010-11-22 18:49:46 +01:00
|
|
|
} while(pos != std::string::npos);
|
2010-10-03 23:04:50 +02:00
|
|
|
return result;
|
|
|
|
}
|