コード例 #1
0
void FHttpRequestWinInet::CancelRequest()
{
	UE_LOG(LogHttp, Log, TEXT("Canceling Http request. %p url=%s"),
			this, *GetURL());

	// force finish/cleanup of request
	// note: will still call completion delegates
	FinishedRequest();
}
コード例 #2
0
bool FHttpRequestWinInet::ProcessRequest()
{
	bool bStarted = false;

	// Disabled http request processing
	if (!FHttpModule::Get().IsHttpEnabled())
	{
		UE_LOG(LogHttp, Verbose, TEXT("Http disabled. Skipping request. url=%s"), *GetURL());
	}
	// Prevent overlapped requests using the same instance
	else if (CompletionStatus == EHttpRequestStatus::Processing)
	{
		UE_LOG(LogHttp, Warning, TEXT("ProcessRequest failed. Still processing last request."));
	}
	// Make sure Internet connection has been setup 
	else if (!FWinInetConnection::Get().IsConnectionValid() &&
			 !FWinInetConnection::Get().InitConnection())
	{
		UE_LOG(LogHttp, Warning, TEXT("ProcessRequest failed. Could not initialize Internet connection."));
	}
	// Nothing to do without a valid URL
	else if (RequestURL.GetURL().IsEmpty())
	{
		UE_LOG(LogHttp, Warning, TEXT("ProcessRequest failed. No URL was specified."));
	}
	// Make sure the URL is parsed correctly with a valid HTTP scheme
	else if (RequestURL.GetURLComponents().nScheme != INTERNET_SCHEME_HTTP &&
			 RequestURL.GetURLComponents().nScheme != INTERNET_SCHEME_HTTPS)
	{
		UE_LOG(LogHttp, Warning, TEXT("ProcessRequest failed. URL '%s' is not a valid HTTP request. %p"), 
			*RequestURL.GetURL(), this);
	}
	else
	{
		// Mark as in-flight to prevent overlapped requests using the same object
		CompletionStatus = EHttpRequestStatus::Processing;
		// Response object to handle data that comes back after starting this request
		Response = MakeShareable(new FHttpResponseWinInet(*this));
		// Add to global list while being processed so that the ref counted request does not get deleted
		FHttpModule::Get().GetHttpManager().AddRequest(SharedThis(this));
		// Try to start the connection and send the Http request
		bStarted = StartRequest();
	}
	
	if (!bStarted)
	{
		// No response since connection failed
		Response = NULL;
		// Cleanup and call delegate
		FinishedRequest();
	}

	// Successfully started the request
	return bStarted;
}
コード例 #3
0
void FHttpRequestWinInet::Tick(float DeltaSeconds)
{
	// keep track of elapsed milliseconds
	const int32 ElapsedMillisecondsThisFrame = DeltaSeconds * 1000;
	FPlatformAtomics::InterlockedAdd(&ElapsedTimeSinceLastServerResponse, ElapsedMillisecondsThisFrame);

	// Update response progress
	if(Response.IsValid())
	{
		int32 ResponseBytes = Response->ProgressBytesRead.GetValue();
		if(ResponseBytes > ProgressBytesSent)
		{
			ProgressBytesSent = ResponseBytes;
			OnRequestProgress().ExecuteIfBound(SharedThis(this),ResponseBytes);
		}
	}

	// Convert to seconds for comparison to the timeout value
	const float TotalElapsedSeconds = ElapsedTimeSinceLastServerResponse / 1000.f;

	const float HttpTimeout = FHttpModule::Get().GetHttpTimeout();
	if (HttpTimeout > 0 && 
		TotalElapsedSeconds >= HttpTimeout)
	{
		UE_LOG(LogHttp, Warning, TEXT("Timeout processing Http request. %p url=%s"),
			this, *GetURL());

		// finish it off since it is timeout
		FinishedRequest();
	}
	// No longer waiting for a response and done processing it
	else if (CompletionStatus == EHttpRequestStatus::Processing &&
		Response.IsValid() &&
		Response->bIsReady)
	{
		FinishedRequest();
	}
}
コード例 #4
0
 void setEnginio(const EnginioClient *enginio)
 {
     if (_enginio) {
         foreach(const QMetaObject::Connection &connection, _connections)
             QObject::disconnect(connection);
         _connections.clear();
     }
     _enginio = const_cast<EnginioClient*>(enginio);
     if (_enginio) {
         _connections.append(QObject::connect(_enginio, &EnginioClient::finished, FinishedRequest(this)));
         _connections.append(QObject::connect(_enginio, &QObject::destroyed, EnginioDestroyed(this)));
         _connections.append(QObject::connect(_enginio, &EnginioClient::backendIdChanged, QueryChanged(this)));
         _connections.append(QObject::connect(_enginio, &EnginioClient::backendSecretChanged, QueryChanged(this)));
         if (!_enginio->backendId().isEmpty() && !_enginio->backendSecret().isEmpty())
             execute();
     }
     emit q->enginioChanged(_enginio);
 }