Example #1
0
 void CompressAndWriteToFile(const std::vector<uint8_t>& uncompressed, const std::string& path)
 {
     const auto compressed = CompressBytes(uncompressed);
     std::ofstream output_file(path, std::ios::out | std::ios::binary);
     output_file.write(reinterpret_cast<const char*>(compressed.data()), (std::streamsize)compressed.size());
     output_file.close();
 }
void UMasterServerFunctions::StartTransmission()
{
	if (RequestQueue.Num() <= 0)
	{
		return;
	}

	bIsBusy = true;
	CurrentRequest = RequestQueue[0];
	RequestQueue.RemoveAt(0);

	if (!Http) return;
	if (!Http->IsHttpEnabled()) return;

	TSharedRef < IHttpRequest > Request = Http->CreateRequest();
	Request->SetVerb(CurrentRequest.RequestVerb);
	Request->SetHeader("User-Agent", "UE4GameClient/1.0");
	Request->SetHeader("Content-Type", "application/json");
	Request->SetURL(TargetHost + CurrentRequest.TheDest);
	Request->SetContent(CompressBytes(CurrentRequest.TheData));

	ServerList.Empty();

	Request->OnProcessRequestComplete().BindUObject(this, &UMasterServerFunctions::OnResponseReceived);
	Request->ProcessRequest();

}
Example #3
0
void HTTPServerSendResponse(STREAM *S, HTTPSession *Session, char *ResponseLine, char *ContentType, char *Body)
{
HTTPSession *Response;
char *Tempstr=NULL;
long ResponseCode=0;

LogToFile(Settings.LogPath,"RESPONSE: '%s' to %s@%s for '%s %s'",ResponseLine,Session->UserName,Session->ClientIP,Session->Method,Session->Path);

ResponseCode=strtol(ResponseLine,NULL,10);

//Create 'Response' rather than using session, because things set by the client in 'Session' might
//get copied into the response and interfere with the response otherwise
Response=HTTPSessionCreate();

/*Copy Values from Session object into Response */
if (Session)
{
	Response->MethodID=Session->MethodID;
	Response->LastModified=Session->LastModified;
	Response->Flags |= Session->Flags & (SESSION_KEEPALIVE | SESSION_AUTHENTICATED);
	//Response->Flags |= SESSION_KEEPALIVE;
	Response->ClientIP=CopyStr(Response->ClientIP,Session->ClientIP);
	Response->Path=CopyStr(Response->Path,Session->Path);
	Response->Method=CopyStr(Response->Method,Session->Method);
	Response->URL=CopyStr(Response->URL,Session->URL);
	Response->UserName=CopyStr(Response->UserName,Session->UserName);
}

Response->ResponseCode=CopyStr(Response->ResponseCode,ResponseLine);
if (ResponseCode==302) SetVar(Response->Headers,"Location",Body);
else Response->ContentSize=StrLen(Body);
Response->ContentType=CopyStr(Response->ContentType,ContentType);


if (HTTPServerDecideToCompress(Session,NULL))
{
  Response->Flags |= SESSION_ENCODE_GZIP;
	Tempstr=SetStrLen(Tempstr,Response->ContentSize *2); 
  Response->ContentSize=CompressBytes(&Tempstr, "gzip",Body, StrLen(Body), 5);
}
else Tempstr=CopyStr(Tempstr,Body);


if ((ResponseCode==401) || (ResponseCode==407)) HTTPServerSendHeaders(S, Response,HEADERS_AUTH);
else HTTPServerSendHeaders(S, Response, HEADERS_KEEPALIVE);

STREAMWriteBytes(S,Tempstr,Response->ContentSize);
STREAMFlush(S);

/* If HTTPServerSendHeaders set SESSION_REUSE then set that in the Session object */
//if (Response->Flags & SESSION_REUSE) Session->Flags |= SESSION_REUSE;
//else Session->Flags &= ~SESSION_REUSE;


ProcessSessionEventTriggers(Response);
HTTPSessionDestroy(Response);

DestroyString(Tempstr);
}