mirror of
				https://github.com/luanti-org/luanti.git
				synced 2025-11-04 01:05:48 +01:00 
			
		
		
		
	Don't allow sync. HTTP requests on the main thread anymore
Any sync. HTTP request on the main thread is a bug, don't allow introducing one again.
This commit is contained in:
		@@ -749,19 +749,6 @@ static void httpfetch_request_clear(u64 caller)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void httpfetch_sync(const HTTPFetchRequest &fetch_request,
 | 
			
		||||
		HTTPFetchResult &fetch_result)
 | 
			
		||||
{
 | 
			
		||||
	// Create ongoing fetch data and make a cURL handle
 | 
			
		||||
	// Set cURL options based on HTTPFetchRequest
 | 
			
		||||
	CurlHandlePool pool;
 | 
			
		||||
	HTTPFetchOngoing ongoing(fetch_request, &pool);
 | 
			
		||||
	// Do the fetch (curl_easy_perform)
 | 
			
		||||
	CURLcode res = ongoing.start(nullptr);
 | 
			
		||||
	// Update fetch result
 | 
			
		||||
	fetch_result = *ongoing.complete(res);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool httpfetch_sync_interruptible(const HTTPFetchRequest &fetch_request,
 | 
			
		||||
		HTTPFetchResult &fetch_result, long interval)
 | 
			
		||||
{
 | 
			
		||||
@@ -779,7 +766,8 @@ bool httpfetch_sync_interruptible(const HTTPFetchRequest &fetch_request,
 | 
			
		||||
		} while (!httpfetch_async_get(req.caller, fetch_result));
 | 
			
		||||
		httpfetch_caller_free(req.caller);
 | 
			
		||||
	} else {
 | 
			
		||||
		httpfetch_sync(fetch_request, fetch_result);
 | 
			
		||||
		throw ModError(std::string("You have tried to execute a synchronous HTTP request on the main thread! "
 | 
			
		||||
				"This offense shall be punished. (").append(fetch_request.url).append(")"));
 | 
			
		||||
	}
 | 
			
		||||
	return true;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user