Skip to content

Commit

Permalink
Added better handling for cancelled requests
Browse files Browse the repository at this point in the history
  • Loading branch information
SMJSGaming committed Jul 12, 2024
1 parent 7ed37a2 commit 4940684
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ jobs:

- uses: actions/upload-artifact@v4
with:
name: GD Intercept Build
name: GDIntercept Build
path: ${{ steps.build.outputs.build-output }}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# GDIntercept Changelog

## v0.3.2-alpha.3 (2024-07-12) - Cancel Support

- Added support for cancelling requests

## v0.3.1-alpha.3 (2024-07-12) - Bugfix Update

- Fixed a bug where certain requests would cause an unallocated reference exception
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")

project(GDIntercept VERSION 0.3.1)
project(GDIntercept VERSION 0.3.2)

file(GLOB_RECURSE SOURCES "src/*.cpp")
add_library(${PROJECT_NAME} SHARED ${SOURCES})
Expand Down
2 changes: 1 addition & 1 deletion mod.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"geode": "3.2.0",
"version": "v0.3.1-alpha.3",
"version": "v0.3.2-alpha.3",
"id": "smjs.gdintercept",
"name": "GDIntercept",
"api": {
Expand Down
7 changes: 4 additions & 3 deletions src/nodes/lists/CaptureList.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "CaptureList.hpp"

size_t CaptureList::active = 1;
size_t CaptureList::active = 0;

CaptureList* CaptureList::create(const CCSize& size, const float cellHeight, const std::function<void(HttpInfo*)>& switchInfo) {
CaptureList* instance = new CaptureList();
Expand Down Expand Up @@ -59,15 +59,16 @@ bool CaptureList::init(const CCSize& size, const float cellHeight, const std::fu
}, "previous_packet"_spr);
#endif

const CCSize listSize = size - 2;
const CCSize listSize = size - 1;
CCTouchDispatcher* dispatcher = CCTouchDispatcher::get();
bool activated = false;

if (!Border::init(LIGHTER_BROWN_4B, size)) {
return false;
}

this->setPadding(1);
this->setPaddingTop(1);
this->setPaddingLeft(1);

for (ProxyHandler* proxy : ProxyHandler::getFilteredProxies()) {
HttpInfo* info = proxy->getInfo();
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/lists/CodeBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ void CodeBlock::onResponse(CCObject* sender) {
if (m_info->responseReceived()) {
this->setCode(m_info->getResponse().getResponseContent(Mod::get()->getSettingValue<bool>("raw-data")));
} else {
this->setCode({ HttpInfo::UNKNOWN_CONTENT, "No response available yet." });
this->setCode({ HttpInfo::UNKNOWN_CONTENT, m_info->getResponse().stringifyStatusCode() });
}

this->updateDataTypeColor('R');
Expand Down
3 changes: 3 additions & 0 deletions src/proxy/HttpInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,10 @@ std::string proxy::HttpInfo::Response::stringifyHeaders() const {

std::string proxy::HttpInfo::Response::stringifyStatusCode() const {
switch (m_statusCode) {
case -3: return "Request Cancelled";
case -2: return "Request Timeout";
case -1: return "Request Error";
case 0: return "No response available yet";
default: return std::to_string(m_statusCode);
}
}
Expand Down
17 changes: 12 additions & 5 deletions src/proxy/ProxyHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,28 +104,35 @@ m_originalProxy(nullptr) {

while (Mod::get()->getSettingValue<bool>("pause-requests")) {
if (cancelled()) {
m_info->m_response.m_statusCode = -3;

return web::WebTask::Cancel();
}

std::this_thread::sleep_for(std::chrono::milliseconds(2));
std::this_thread::sleep_for(std::chrono::milliseconds(5));
}

m_modRequest->send(m_info->getRequest().getURL().getMethod(), url).listen([&response](web::WebResponse* taskResponse) {
web::WebTask task = m_modRequest->send(m_info->getRequest().getURL().getMethod(), url);
m_info->resume();

task.listen([&response](web::WebResponse* taskResponse) {
response = new web::WebResponse(*taskResponse);
}, [progress](web::WebProgress* taskProgress) {
progress(*taskProgress);
});
m_info->resume();

while (!response) {
if (cancelled()) {
return web::WebTask::Cancel();
break;
}

std::this_thread::sleep_for(std::chrono::milliseconds(5));
std::this_thread::sleep_for(std::chrono::milliseconds(2));
}

if (cancelled()) {
task.cancel();
m_info->m_response.m_statusCode = -3;

return web::WebTask::Cancel();
} else {
this->onModResponse(response);
Expand Down

0 comments on commit 4940684

Please sign in to comment.