Fix content-length zero error

This commit is contained in:
Respirant
2021-01-08 21:13:57 +03:00
parent d81197783f
commit 4d3dbd0774
3 changed files with 9 additions and 4 deletions
@@ -31,7 +31,6 @@
"BlacklistPlatforms": [ "BlacklistPlatforms": [
"XboxOne", "XboxOne",
"PS4", "PS4",
"HTML5",
"TVOS", "TVOS",
"Switch" "Switch"
] ]
@@ -30,10 +30,11 @@ URuntimeFilesDownloaderLibrary* URuntimeFilesDownloaderLibrary::DownloadFile(con
FileUrl = URL; FileUrl = URL;
FileSavePath = SavePath; FileSavePath = SavePath;
TSharedRef< IHttpRequest, ESPMode::ThreadSafe > HttpRequest = FHttpModule::Get().CreateRequest(); TSharedRef< IHttpRequest > HttpRequest = FHttpModule::Get().CreateRequest();
HttpRequest->SetVerb("GET"); HttpRequest->SetVerb("GET");
HttpRequest->SetURL(URL); HttpRequest->SetURL(URL);
HttpRequest->SetHeader("Content-Type", TEXT("application/octet-stream"));
HttpRequest->OnProcessRequestComplete().BindUObject(this, &URuntimeFilesDownloaderLibrary::OnReady_Internal); HttpRequest->OnProcessRequestComplete().BindUObject(this, &URuntimeFilesDownloaderLibrary::OnReady_Internal);
HttpRequest->OnRequestProgress().BindUObject(this, &URuntimeFilesDownloaderLibrary::OnProgress_Internal); HttpRequest->OnRequestProgress().BindUObject(this, &URuntimeFilesDownloaderLibrary::OnProgress_Internal);
@@ -46,8 +47,12 @@ URuntimeFilesDownloaderLibrary* URuntimeFilesDownloaderLibrary::DownloadFile(con
void URuntimeFilesDownloaderLibrary::OnProgress_Internal(FHttpRequestPtr Request, int32 BytesSent, int32 BytesReceived) void URuntimeFilesDownloaderLibrary::OnProgress_Internal(FHttpRequestPtr Request, int32 BytesSent, int32 BytesReceived)
{ {
int32 FullSize = Request->GetContentLength(); FHttpResponsePtr Response = Request->GetResponse();
OnProgress.Broadcast(BytesSent, BytesReceived, FullSize); if (Response.IsValid())
{
int32 FullSize = Response->GetContentLength();
OnProgress.Broadcast(BytesSent, BytesReceived, FullSize);
}
} }
void URuntimeFilesDownloaderLibrary::OnReady_Internal(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful) void URuntimeFilesDownloaderLibrary::OnReady_Internal(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
@@ -5,6 +5,7 @@
#include "Http.h" #include "Http.h"
#include "Misc/Paths.h" #include "Misc/Paths.h"
#include "HAL/PlatformFilemanager.h" #include "HAL/PlatformFilemanager.h"
#include "GenericPlatform/GenericPlatformFile.h"
#include "RuntimeFilesDownloaderLibrary.generated.h" #include "RuntimeFilesDownloaderLibrary.generated.h"
/** /**