|
2 | 2 | #include "UnrealEnginePythonPrivatePCH.h" |
3 | 3 |
|
4 | 4 |
|
5 | | -/* |
6 | | -static PyObject *py_ue_ihttp_request_set_verb(ue_PyIHttpRequest *self, PyObject * args) { |
7 | | -
|
8 | | - char *verb; |
9 | | - if (!PyArg_ParseTuple(args, "s:set_verb", &verb)) { |
10 | | - return NULL; |
11 | | - } |
12 | | -
|
13 | | - self->http_request->SetVerb(UTF8_TO_TCHAR(verb)); |
14 | | -
|
15 | | - Py_INCREF(Py_None); |
16 | | - return Py_None; |
| 5 | +static PyObject *py_ue_ihttp_base_get_content_length(ue_PyIHttpBase *self, PyObject * args) { |
| 6 | + return PyLong_FromLong((int)self->http_base->GetContentLength()); |
17 | 7 | } |
18 | 8 |
|
19 | | -static PyObject *py_ue_ihttp_request_set_url(ue_PyIHttpRequest *self, PyObject * args) { |
20 | | -
|
21 | | - char *url; |
22 | | - if (!PyArg_ParseTuple(args, "s:set_url", &url)) { |
23 | | - return NULL; |
24 | | - } |
| 9 | +static PyObject *py_ue_ihttp_base_get_url(ue_PyIHttpBase *self, PyObject * args) { |
| 10 | + return PyUnicode_FromString(TCHAR_TO_UTF8(*self->http_base->GetURL())); |
| 11 | +} |
25 | 12 |
|
26 | | - self->http_request->SetURL(UTF8_TO_TCHAR(url)); |
| 13 | +static PyObject *py_ue_ihttp_base_get_content_type(ue_PyIHttpBase *self, PyObject * args) { |
| 14 | + return PyUnicode_FromString(TCHAR_TO_UTF8(*self->http_base->GetContentType())); |
| 15 | +} |
27 | 16 |
|
28 | | - Py_INCREF(Py_None); |
29 | | - return Py_None; |
| 17 | +static PyObject *py_ue_ihttp_base_get_content(ue_PyIHttpBase *self, PyObject * args) { |
| 18 | + TArray<uint8> data = self->http_base->GetContent(); |
| 19 | + return PyBytes_FromStringAndSize((char *)data.GetData(), data.Num()); |
30 | 20 | } |
31 | 21 |
|
32 | | -static PyObject *py_ue_ihttp_request_set_header(ue_PyIHttpRequest *self, PyObject * args) { |
| 22 | +static PyObject *py_ue_ihttp_base_get_header(ue_PyIHttpBase *self, PyObject * args) { |
33 | 23 |
|
34 | 24 | char *key; |
35 | | - char *value; |
36 | | - if (!PyArg_ParseTuple(args, "ss:set_header", &key, &value)) { |
| 25 | + if (!PyArg_ParseTuple(args, "s:get_header", &key)) { |
37 | 26 | return NULL; |
38 | 27 | } |
39 | 28 |
|
40 | | - self->http_request->SetHeader(UTF8_TO_TCHAR(key), UTF8_TO_TCHAR(value)); |
41 | | -
|
42 | | - Py_INCREF(Py_None); |
43 | | - return Py_None; |
| 29 | + return PyUnicode_FromString(TCHAR_TO_UTF8(*self->http_base->GetHeader(UTF8_TO_TCHAR(key)))); |
44 | 30 | } |
45 | 31 |
|
46 | | -static PyObject *py_ue_ihttp_request_append_to_header(ue_PyIHttpRequest *self, PyObject * args) { |
| 32 | +static PyObject *py_ue_ihttp_base_get_url_parameter(ue_PyIHttpBase *self, PyObject * args) { |
47 | 33 |
|
48 | 34 | char *key; |
49 | | - char *value; |
50 | | - if (!PyArg_ParseTuple(args, "ss:append_to_header", &key, &value)) { |
| 35 | + if (!PyArg_ParseTuple(args, "s:get_url_parameter", &key)) { |
51 | 36 | return NULL; |
52 | 37 | } |
53 | 38 |
|
54 | | - self->http_request->AppendToHeader(UTF8_TO_TCHAR(key), UTF8_TO_TCHAR(value)); |
55 | | -
|
56 | | - Py_INCREF(Py_None); |
57 | | - return Py_None; |
| 39 | + return PyUnicode_FromString(TCHAR_TO_UTF8(*self->http_base->GetURLParameter(UTF8_TO_TCHAR(key)))); |
58 | 40 | } |
59 | 41 |
|
60 | | -static PyObject *py_ue_ihttp_request_set_content(ue_PyIHttpRequest *self, PyObject * args) { |
61 | | -
|
62 | | - PyObject *py_obj; |
63 | | - if (!PyArg_ParseTuple(args, "O:set_content", &py_obj)) { |
64 | | - return NULL; |
65 | | - } |
66 | | -
|
67 | | - if (PyUnicode_Check(py_obj)) { |
68 | | - self->http_request->SetContentAsString(UTF8_TO_TCHAR(PyUnicode_AsUTF8(py_obj))); |
| 42 | +static PyObject *py_ue_ihttp_base_get_all_headers(ue_PyIHttpBase *self, PyObject * args) { |
| 43 | + TArray<FString> headers = self->http_base->GetAllHeaders(); |
| 44 | + PyObject *py_headers = PyList_New(0); |
| 45 | + return PyUnicode_FromString(TCHAR_TO_UTF8(*self->http_base->GetContentType())); |
| 46 | + for (FString item : headers) { |
| 47 | + PyObject *py_header = PyUnicode_FromString(TCHAR_TO_UTF8(*item)); |
| 48 | + PyList_Append(py_headers, py_header); |
| 49 | + Py_DECREF(py_header); |
69 | 50 | } |
70 | | - else if (PyBytes_Check(py_obj)) { |
71 | | - char *buf = nullptr; |
72 | | - Py_ssize_t len = 0; |
73 | | - PyBytes_AsStringAndSize(py_obj, &buf, &len); |
74 | | - TArray<uint8> data; |
75 | | - data.Append((uint8 *)buf, len); |
76 | | - self->http_request->SetContent(data); |
77 | | - } |
78 | | -
|
79 | | - Py_INCREF(Py_None); |
80 | | - return Py_None; |
| 51 | + return py_headers; |
81 | 52 | } |
82 | 53 |
|
83 | | -static PyObject *py_ue_ihttp_request_tick(ue_PyIHttpRequest *self, PyObject * args) { |
84 | | -
|
85 | | - float delta_seconds; |
86 | | - if (!PyArg_ParseTuple(args, "f:tick", &delta_seconds)) { |
87 | | - return NULL; |
88 | | - } |
89 | | -
|
90 | | - self->http_request->Tick(delta_seconds); |
91 | | -
|
92 | | - Py_INCREF(Py_None); |
93 | | - return Py_None; |
94 | | -} |
95 | | -
|
96 | | -static PyObject *py_ue_ihttp_request_process_request(ue_PyIHttpRequest *self, PyObject * args) { |
97 | | - self->http_request->ProcessRequest(); |
98 | | -
|
99 | | - Py_INCREF(Py_None); |
100 | | - return Py_None; |
101 | | -} |
102 | | -
|
103 | | -static PyObject *py_ue_ihttp_request_cancel_request(ue_PyIHttpRequest *self, PyObject * args) { |
104 | | - self->http_request->CancelRequest(); |
105 | | -
|
106 | | - Py_INCREF(Py_None); |
107 | | - return Py_None; |
108 | | -}*/ |
109 | | - |
110 | | -static PyObject *py_ue_ihttp_base_get_content_length(ue_PyIHttpBase *self, PyObject * args) { |
111 | | - return PyLong_FromLong((int)self->http_base->GetContentLength()); |
112 | | -} |
113 | | - |
114 | | - |
115 | | - |
116 | 54 | static PyMethodDef ue_PyIHttpBase_methods[] = { |
117 | | - //{ "get_content", (PyCFunction)py_ue_ihttp_base_get_content, METH_VARARGS, "" }, |
118 | | - //{ "get_all_headers", (PyCFunction)py_ue_ihttp_base_get_all_headers, METH_VARARGS, "" }, |
| 55 | + { "get_content", (PyCFunction)py_ue_ihttp_base_get_content, METH_VARARGS, "" }, |
| 56 | + { "get_all_headers", (PyCFunction)py_ue_ihttp_base_get_all_headers, METH_VARARGS, "" }, |
119 | 57 | { "get_content_length", (PyCFunction)py_ue_ihttp_base_get_content_length, METH_VARARGS, "" }, |
120 | | - //{ "get_content_type", (PyCFunction)py_ue_ihttp_base_get_content_type, METH_VARARGS, "" }, |
121 | | - //{ "get_header", (PyCFunction)py_ue_ihttp_base_get_header, METH_VARARGS, "" }, |
122 | | - //{ "get_url", (PyCFunction)py_ue_ihttp_base_get_url, METH_VARARGS, "" }, |
123 | | - //{ "get_url_parameter", (PyCFunction)py_ue_ihttp_base_get_url_parameter, METH_VARARGS, "" }, |
| 58 | + { "get_content_type", (PyCFunction)py_ue_ihttp_base_get_content_type, METH_VARARGS, "" }, |
| 59 | + { "get_header", (PyCFunction)py_ue_ihttp_base_get_header, METH_VARARGS, "" }, |
| 60 | + { "get_url", (PyCFunction)py_ue_ihttp_base_get_url, METH_VARARGS, "" }, |
| 61 | + { "get_url_parameter", (PyCFunction)py_ue_ihttp_base_get_url_parameter, METH_VARARGS, "" }, |
124 | 62 | { NULL } /* Sentinel */ |
125 | 63 | }; |
126 | 64 |
|
127 | 65 |
|
128 | 66 | static PyObject *ue_PyIHttpBase_str(ue_PyIHttpBase *self) |
129 | 67 | { |
| 68 | + char *s = (char*)""; |
| 69 | + FString url = self->http_base->GetURL(); |
| 70 | + if (!url.IsEmpty()) { |
| 71 | + s = TCHAR_TO_UTF8(*url); |
| 72 | + } |
130 | 73 | return PyUnicode_FromFormat("<unreal_engine.IHttpBase {'url': '%s'}>", |
131 | | - PyUnicode_FromString(TCHAR_TO_UTF8(*self->http_base->GetURL()))); |
| 74 | + PyUnicode_FromString(s)); |
132 | 75 | } |
133 | 76 |
|
134 | 77 | PyTypeObject ue_PyIHttpBaseType = { |
|
0 commit comments