@@ -145,6 +145,22 @@ void UPythonHttpDelegate::OnRequestComplete(FHttpRequestPtr request, FHttpRespon
145145 Py_DECREF (ret);
146146}
147147
148+ void UPythonHttpDelegate::OnRequestProgress (FHttpRequestPtr request, int32 sent, int32 received) {
149+ FScopePythonGIL gil;
150+
151+ if (!request.IsValid ()) {
152+ UE_LOG (LogPython, Error, TEXT (" Unable to retrieve HTTP infos" ));
153+ return ;
154+ }
155+
156+ PyObject *ret = PyObject_CallFunction (py_callable, (char *)" Oii" , py_http_request, sent, received);
157+ if (!ret) {
158+ unreal_engine_py_log_error ();
159+ return ;
160+ }
161+ Py_DECREF (ret);
162+ }
163+
148164static PyObject *py_ue_ihttp_request_bind_on_process_request_complete (ue_PyIHttpRequest *self, PyObject * args) {
149165
150166 PyObject *py_callable;
@@ -166,8 +182,30 @@ static PyObject *py_ue_ihttp_request_bind_on_process_request_complete(ue_PyIHttp
166182 return Py_None;
167183}
168184
185+ static PyObject *py_ue_ihttp_request_bind_on_request_progress (ue_PyIHttpRequest *self, PyObject * args) {
186+
187+ PyObject *py_callable;
188+ if (!PyArg_ParseTuple (args, " O:bind_on_request_progress" , &py_callable)) {
189+ return NULL ;
190+ }
191+
192+ if (!PyCallable_Check (py_callable)) {
193+ return PyErr_Format (PyExc_Exception, " argument is not a callable" );
194+ }
195+
196+ UPythonHttpDelegate *py_delegate = NewObject<UPythonHttpDelegate>();
197+ py_delegate->SetPyCallable (py_callable);
198+ // this trick avoids generating a new python object
199+ py_delegate->SetPyHttpRequest (self);
200+ self->http_request ->OnRequestProgress ().BindUObject (py_delegate, &UPythonHttpDelegate::OnRequestProgress);
201+
202+ Py_INCREF (Py_None);
203+ return Py_None;
204+ }
205+
169206static PyMethodDef ue_PyIHttpRequest_methods[] = {
170207 { " bind_on_process_request_complete" , (PyCFunction)py_ue_ihttp_request_bind_on_process_request_complete, METH_VARARGS, " " },
208+ { " bind_on_request_progress" , (PyCFunction)py_ue_ihttp_request_bind_on_request_progress, METH_VARARGS, " " },
171209 { " append_to_header" , (PyCFunction)py_ue_ihttp_request_append_to_header, METH_VARARGS, " " },
172210 { " cancel_request" , (PyCFunction)py_ue_ihttp_request_cancel_request, METH_VARARGS, " " },
173211 { " get_elapsed_time" , (PyCFunction)py_ue_ihttp_request_get_elapsed_time, METH_VARARGS, " " },
0 commit comments