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.
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
#include "cefclient/string_util.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include <sstream>
|
2012-01-10 00:46:23 +01:00
|
|
|
#include <string>
|
|
|
|
#include "include/cef_request.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void DumpRequestContents(CefRefPtr<CefRequest> request, std::string& str) {
|
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);
|
2012-01-10 00:46:23 +01:00
|
|
|
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();
|
2012-01-10 00:46:23 +01:00
|
|
|
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();
|
2012-01-10 00:46:23 +01:00
|
|
|
if (postData.get()) {
|
2010-10-03 23:04:50 +02:00
|
|
|
CefPostData::ElementVector elements;
|
|
|
|
postData->GetElements(elements);
|
2012-01-10 00:46:23 +01:00
|
|
|
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();
|
2012-01-10 00:46:23 +01:00
|
|
|
for (; it != elements.end(); ++it) {
|
2010-10-03 23:04:50 +02:00
|
|
|
element = (*it);
|
2012-01-10 00:46:23 +01:00
|
|
|
if (element->GetType() == PDE_TYPE_BYTES) {
|
2010-10-03 23:04:50 +02:00
|
|
|
// the element is composed of bytes
|
2010-11-22 18:49:46 +01:00
|
|
|
ss << "\n\tBytes: ";
|
2012-01-10 00:46:23 +01:00
|
|
|
if (element->GetBytesCount() == 0) {
|
2010-11-22 18:49:46 +01:00
|
|
|
ss << "(empty)";
|
2012-01-10 00:46:23 +01:00
|
|
|
} else {
|
2010-10-03 23:04:50 +02:00
|
|
|
// 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;
|
|
|
|
}
|
2012-01-10 00:46:23 +01:00
|
|
|
} 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,
|
2012-01-10 00:46:23 +01:00
|
|
|
const std::string& to) {
|
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);
|
2012-01-10 00:46:23 +01:00
|
|
|
if (pos != std::string::npos) {
|
2010-10-03 23:04:50 +02:00
|
|
|
result.replace(pos, from_len, to);
|
|
|
|
pos += to_len;
|
|
|
|
}
|
2012-01-10 00:46:23 +01:00
|
|
|
} while (pos != std::string::npos);
|
2010-10-03 23:04:50 +02:00
|
|
|
return result;
|
|
|
|
}
|