Does HttpRequest use HttpManager by default?

I am currently implementing a queue of HttpRequests to avoid bottlenecking the system. When one request is complete, the next is taken from the queue, and no more than one is ever being processed at any given time.

However, it looks like HttpManager is doing a similar thing already. So…does IHttpRequest.ProcessRequest() use the HttpManager behind the scenes? Can I safely just begin processing HttpRequests as soon as I receive them, knowing they are being “managed” correctly? Or should I still use a queue?

The HttpManager doesn’t do anything to bottleneck or serialize the requests being made at the same. It simply allows all of the requests to get a chance to tick, which is to say it’s looking for a timeout or notification that the request is done (via the callback the request gets from a lower level http library).

If you want to queue them up, you have to do that yourself. That being said, here is some simple code for that.

bool YourClass::QueueRequest(FHttpRequestPtr HttpRequest, bool& bSuccess)
{
	bSuccess = true;
	PendingRequests.Add(HttpRequest);
	if (PendingRequests.Num() == 1)
	{
		bSuccess = HttpRequest->ProcessRequest();
		return true;
	}
	return false;
}

bool YourClass::ProcessNextRequest()
{
	if (PendingRequests.Num() > 0)
	{
		// Remove entry that just called this after finishing
		FHttpRequestPtr HttpRequest = PendingRequests[0];
		PendingRequests.RemoveAt(0);
		if (PendingRequests.Num() > 0)
		{
			FHttpRequestPtr HttpRequest = PendingRequests[0];
			return HttpRequest->ProcessRequest();
		}
	}
	return false;
}

Just call QueueRequest anywhere you were calling ProcessRequest, and be sure to call ProcessNextRequest when the last one completes. Now all calls will work serially.

Thank you for the response and for the code! That looks similar to what I was doing so I’m glad I’m on the right track. Just wanted to make sure I wasn’t reinventing the wheel here :slight_smile: