forked from cefsharp/CefSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRequest.cpp
More file actions
91 lines (71 loc) · 2.31 KB
/
Copy pathRequest.cpp
File metadata and controls
91 lines (71 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "Stdafx.h"
#include "Request.h"
namespace CefSharp
{
String^ CefRequestWrapper::Url::get()
{
return toClr(_wrappedRequest->GetURL());
}
void CefRequestWrapper::Url::set(String^ url)
{
if (url == nullptr)
{
throw gcnew System::ArgumentException("cannot be null", "url");
}
CefString str = toNative(url);
_wrappedRequest->SetURL(str);
}
String^ CefRequestWrapper::Method::get()
{
return toClr(_wrappedRequest->GetMethod());
}
String^ CefRequestWrapper::Body::get()
{
CefPostData::ElementVector ev;
CefRefPtr<CefPostData> data = _wrappedRequest->GetPostData();
if (data.get() != nullptr)
{
data.get()->GetElements(ev);
for (CefPostData::ElementVector::iterator it = ev.begin(); it != ev.end(); ++it)
{
CefPostDataElement *el = it->get();
if (el->GetType() == PDE_TYPE_BYTES)
{
size_t count = el->GetBytesCount();
char* bytes = new char[count];
el->GetBytes(count, bytes);
return gcnew String(bytes, 0, count);
}
else if (el->GetType() == PDE_TYPE_FILE)
{
return toClr(el->GetFile());
}
}
}
return nullptr;
}
IDictionary<String^, String^>^ CefRequestWrapper::GetHeaders()
{
CefRequest::HeaderMap hm;
_wrappedRequest->GetHeaderMap(hm);
IDictionary<String^, String^>^ headers = gcnew Dictionary<String^, String^>();
for (CefRequest::HeaderMap::iterator it = hm.begin(); it != hm.end(); ++it)
{
String^ name = toClr(it->first);
String^ value = toClr(it->second);
headers[name] = value;
}
return headers;
}
void CefRequestWrapper::SetHeaders(IDictionary<String^, String^>^ headers)
{
CefRequest::HeaderMap hm;
for each(KeyValuePair<String^, String^>^ pair in headers)
{
CefString name = toNative(pair->Key);
CefString value = toNative(pair->Value);
hm.insert(std::make_pair(name, value));
}
_wrappedRequest->SetHeaderMap(hm);
}
}