Files
UnrealEngineUWP/Engine/Source/Programs/DotNETCommon/DotNETUtilities/SimpleWebRequest.cs
Robert Manuszewski f4fb4b8596 Copying //UE4/Dev-Core to //UE4/Dev-Main (Source: //UE4/Dev-Core @ 2996057)
==========================
MAJOR FEATURES + CHANGES
==========================

Change 2975196 on 2016/05/12 by Robert.Manuszewski

	Garbage Collector will no longer be responsible for generating class token stream, instead the token stream will be generated on startup or when a class has finished loading.

	- This way we can avoid very long GC times after new blueprints have been loaded.
	- Temporarily enabled CLASS_TokenStreamAssembled check in development builds (for testing purposes)

Change 2993960 on 2016/05/30 by Robert.Manuszewski

	Fixing leaked linkers created by blocking load requests during async loading.

Change 2959398 on 2016/04/28 by Steve.Robb

	TMap references are strong and cannot be nulled by pending kill.  This makes references in values strong too, even though we only really care about keys, which will corrupt the map when nulled.

	#jira UE-20828

Change 2960723 on 2016/04/29 by Graeme.Thornton

	Fix for texture asset import data being ignored when async loaded

Change 2960938 on 2016/04/29 by Robert.Manuszewski

	Nulling out sql db handle after closing it.

Change 2967127 on 2016/05/05 by Steve.Robb

	Move constructors explicitly disabled in generated code.

Change 2967143 on 2016/05/05 by Steve.Robb

	Static analysis fixes:

	warning C6326: Potential comparison of a constant with another constant.

Change 2967164 on 2016/05/05 by Steve.Robb

	Static analysis fixes:

	warning C6011: Dereferencing NULL pointer

Change 2968650 on 2016/05/06 by Steve.Robb

	Fix for HotReload copying module manager.

Change 2968915 on 2016/05/06 by Robert.Manuszewski

	Fixing spelling of SetImageIntegrityStatus function name.

Change 2970406 on 2016/05/09 by Steve.Robb

	Static analysis fixes:

	Function uses '...' bytes of stack:  exceeds /analyze:stacksize '81940'.  Consider moving some data to heap.

Change 2970419 on 2016/05/09 by Steve.Robb

	Static analysis fixes:

	warning C6326: Potential comparison of a constant with another constant.
	warning C6011: Dereferencing NULL pointer '...'.
	warning C6385: Reading invalid data from '...':  the readable size is '...' bytes, but '...' bytes may be read.
	warning C6386: Buffer overrun while writing to '...':  the writable size is '...' bytes, but '...' bytes might be written.

Change 2970431 on 2016/05/09 by Steve.Robb

	Static analysis fixes:

	warning C6299: Explicitly comparing a bit field to a Boolean type will yield unexpected results.

Change 2972032 on 2016/05/10 by Steven.Hutton

	Workflow fixes to bugg / crashgroup filtering. Filters should now correctly persist across queries.

Change 2972085 on 2016/05/10 by Steve.Robb

	Const-correctness fix for FLogCategoryBase::IsSuppressed.

Change 2972087 on 2016/05/10 by Steve.Robb

	ELogVerbosity moved into its own header.

Change 2972090 on 2016/05/10 by Steve.Robb

	Redundant ensure removed.

Change 2972103 on 2016/05/10 by Steve.Robb

	Removal of redundant use of USING_CODE_ANALYSIS.

Change 2972139 on 2016/05/10 by Steve.Robb

	Fix for ensure macros throwing C6326 warnings during static analysis.

Change 2972147 on 2016/05/10 by Steve.Robb

	Fix for UE_LOG_ACTIVE macro throwing C6326 warnings during static analysis.

Change 2972162 on 2016/05/10 by Steve.Robb

	SCOPE_CYCLE_COUNTER_GUARD removed.

Change 2972168 on 2016/05/10 by Steve.Robb

	Compile error fix for logOrEnsureNanError in static analysis builds.

Change 2973084 on 2016/05/10 by Chris.Wood

	Crash Report Server performance tweak

Change 2974030 on 2016/05/11 by Steve.Robb

	Fix for IPropertyHandle::SetValue - used to take a non-const reference to a const UObject*, now it takes const references to both non-const and const UObject*.

Change 2974053 on 2016/05/11 by Steve.Robb

	Static analysis fixes:

	warning C6326: Potential comparison of a constant with another constant.

Change 2974191 on 2016/05/11 by Steve.Robb

	Fix for template instantiation error in VS2013.

Change 2975298 on 2016/05/12 by Steve.Robb

	Static analysis fixes:

	warning C6236: (<expression> || <non-zero constant>) is always a non-zero constant.

Change 2975318 on 2016/05/12 by Steve.Robb

	Fix for hot reload info being reported as warnings.

	#jira UE-30586

Change 2975447 on 2016/05/12 by Steve.Robb

	Static analysis fixes:

	warning C6235: (<non-zero constant> || <expression>) is always a non-zero constant.
	warning C6239: (<non-zero constant> && <expression>) always evaluates to the result of <expression>.  Did you intend to use the bitwise-and operator?
	warning C6240: (<expression> && <non-zero constant>) always evaluates to the result of <expression>.  Did you intend to use the bitwise-and operator?
	warning C6285: (<non-zero constant> || <non-zero constant>) is always a non-zero constant.  Did you intend to use the bitwise-and operator?
	warning C6286: (<non-zero constant> || <expression>) is always a non-zero constant.  <expression> is never evaluated and might have side effects.
	warning C6289: Incorrect operator:  mutual exclusion over || is always a non-zero constant.  Did you intend to use && instead?
	warning C6316: Incorrect operator:  tested expression is constant and non-zero.  Use bitwise-and to determine whether bits are set.

Change 2975478 on 2016/05/12 by Steve.Robb

	Static analysis fixes for lots of redundant <zero constant> and <non-zero constant> warnings.

Change 2975538 on 2016/05/12 by Steve.Robb

	Static analysis fixes:

	warning C6011: Dereferencing NULL pointer 'StaticResource'

Change 2976640 on 2016/05/13 by Robert.Manuszewski

	Fixing crashes caused by token stream generation changes. Making sure the token stream gets re-generated when a class gets re-linked.

	#jira UE-30675

Change 2978320 on 2016/05/16 by Steve.Robb

	Fix for static analysis warnings in XNA headers.

Change 2978329 on 2016/05/16 by Steve.Robb

	Static analysis fixes:

	warning C6334: sizeof operator applied to an expression with an operator might yield unexpected results:  Parentheses can be used to disambiguate certain usages.

Change 2980222 on 2016/05/17 by Steve.Robb

	Static analysis fixes:

	warning C6011: Dereferencing NULL pointer 'X'.
	warning C28182: Dereferencing NULL pointer. 'X' contains the same NULL value as 'Y' did.

Change 2980458 on 2016/05/17 by Chris.Wood

	Attempt to fix crash report submission problems from CRP to CR website
	[UE-30257] - Crashreports are sometimes missing file attachments

	Passing crash GUID so that website can easily check for duplicates in future
	Increased request timeout for AddCrash to be longer than website database timeout
	Logging retries for future visibility
	CRP v.1.1.6

Change 2980639 on 2016/05/17 by Steve.Robb

	Static analysis fixes:

	warning C6011: Dereferencing NULL pointer 'X'.
	warning C28182: Dereferencing NULL pointer. 'X' contains the same NULL value as 'Y' did.

Change 2981750 on 2016/05/18 by Steve.Robb

	check()s in ContainerAllocationPolicies.h changed to checkSlow()s, as they only exist to check that the container has been written correctly.

Change 2982106 on 2016/05/18 by John.Mahoney

	Fixed a crash caused by loading two stat capture files simultaneously in the profiler.
	If the user tries to load a capture file while another load is in progress, the previous load is now cancelled and cleaned up before proceeding with the new load.
	Made the delegates in FNewStatsReader explicitly specify which profiler instance they are loading data for, instead of relying on the current value of LoadConnection->InstanceId.
	This also fixes a crash that occurs when selecting a different capture file in the "Stats dump browser" pane of the profiler (after using Load Folder) while another file is still loading.
	Cleaned up some weak pointer usage in the profiler window.

	#jira UE-30741

Change 2983366 on 2016/05/19 by Steven.Hutton

	Changes for passing crash type directly from CRP to CRW.

Change 2983394 on 2016/05/19 by Steven.Hutton

	Minor changes to add crash with more error reporting

Change 2984685 on 2016/05/20 by Robert.Manuszewski

	Merging //UE4/Dev-Main @ 2984626 to Dev-Core (//UE4/Dev-Core)

Change 2985143 on 2016/05/20 by Steve.Robb

	Missing semi-colons.

Change 2986463 on 2016/05/23 by Steve.Robb

	CopyTemp added to make it clear that you want to make a copy (rather than a move, or an accidental copy) at the call site of a function taking rvalue refs.

Change 2986475 on 2016/05/23 by Steve.Robb

	Static analysis fixes:

	warning C6313: Incorrect operator:  zero-valued flag cannot be tested with bitwise-and.

Change 2986476 on 2016/05/23 by Steve.Robb

	Static analysis fixes:

	warning C6313: Incorrect operator:  zero-valued flag cannot be tested with bitwise-and.

Change 2986480 on 2016/05/23 by Steve.Robb

	Static analysis fixes:

	warning C6326: Potential comparison of a constant with another constant

Change 2986515 on 2016/05/23 by Steve.Robb

	Static analysis fixes:

	warning C6340: Mismatch on sign: 'X' passed as _Param_(N) when some unsigned type is required in call to 'Func'

Change 2986680 on 2016/05/23 by Steve.Robb

	Static analysis fixes:

	warning C6386: Buffer overrun while writing to 'Ptr':  the writable size is 'X' bytes, but 'Y' bytes might be written.
	warning C6387: 'Ptr' could be '0':  this does not adhere to the specification for the function 'Func'
	warning C6031: Return value ignored: 'snprintf'.
	warning C6340: Mismatch on sign: 'const unsigned int' passed as _Param_(4) when some signed type is required in call to 'snprintf'.

Change 2986865 on 2016/05/23 by Robert.Manuszewski

	Removing redundand AddReferencedObjects functions

Change 2987968 on 2016/05/24 by Robert.Manuszewski

	Removing redundant UPROPERTY macros from intrinsic classes.

Change 2987979 on 2016/05/24 by Steve.Robb

	Optimization of some FString and FPaths operations to produce fewer temporaries.

Change 2988297 on 2016/05/24 by Steve.Robb

	Static analysis fixes:

	warning C6287: Redundant code:  the left and right sub-expressions are identical.

Change 2988430 on 2016/05/24 by Steve.Robb

	Static analysis fixes:

	warning C6385: Reading invalid data from 'var':  the readable size is 'X' bytes, but 'Y' bytes may be read.

Change 2988461 on 2016/05/24 by Steve.Robb

	Static analysis fixes:

	warning C6235: (<non-zero constant> || <expression>) is always a non-zero constant.
	warning C6239: (<non-zero constant> && <expression>) always evaluates to the result of <expression>.
	warning C6240: (<expression> && <non-zero constant>) always evaluates to the result of <expression>.

Change 2988464 on 2016/05/24 by Steve.Robb

	Static analysis fixes:

	warning C6262: Function uses 'X' bytes of stack:  exceeds /analyze:stacksize 'Y'.  Consider moving some data to heap.

Change 2988494 on 2016/05/24 by Steve.Robb

	Static analysis fixes:

	warning C6237: (<zero> && <expression>) is always zero.  <expression> is never evaluated and might have side effects.

Change 2989411 on 2016/05/25 by Robert.Manuszewski

	Splitting GC cluster index and intenral object flags to allow more UObjects in editor builds.

Change 2989429 on 2016/05/25 by Steve.Robb

	Static analysis fixes:

	warning C6387: '_Param_(X)' could be '0':  this does not adhere to the specification for the function 'Func'.

Change 2989982 on 2016/05/25 by Steve.Robb

	Static analysis fixes:

	warning C6001: Using uninitialized memory 'LODPlanesMin'.

Change 2990018 on 2016/05/25 by Steve.Robb

	Static analysis fixes:

	warning C6386: Buffer overrun while writing to 'X'

Change 2990077 on 2016/05/25 by Steve.Robb

	Static analysis fixes:

	warning C6240: (<expression> && <non-zero constant>) always evaluates to the result of <expression>.
	warning C6011: Dereferencing NULL pointer 'Ptr'.

Change 2990114 on 2016/05/25 by Steve.Robb

	Static analysis fixes:

	warning C6336: Arithmetic operator has precedence over question operator, use parentheses to clarify intent.

Change 2990125 on 2016/05/25 by Steve.Robb

	Static analysis fixes:

	warning C6239: (<non-zero constant> && <expression>) always evaluates to the result of <expression>.

Change 2990162 on 2016/05/25 by Steve.Robb

	Static analysis fixes:

	warning C6294: Ill-defined for-loop:  initial condition does not satisfy test.  Loop body not executed.

Change 2990193 on 2016/05/25 by Steve.Robb

	Static analysis fixes:

	warning C28182: Dereferencing NULL pointer. 'type' contains the same NULL value as 'type->base_type' did.
	warning C6011: Dereferencing NULL pointer 'Semantic'.

Change 2991006 on 2016/05/26 by Steve.Robb

	Static analysis fixes:

	warning C28113: Accessing a local variable dummy via an Interlocked function:  This is an unusual usage which could be reconsidered.

Change 2991012 on 2016/05/26 by Steve.Robb

	Static analysis fixes:

	warning C6031: Return value ignored: 'InitializeCriticalSectionAndSpinCount'.

Change 2991013 on 2016/05/26 by Steve.Robb

	Static analysis fixes:

	warning C6287: Redundant code:  the left and right sub-expressions are identical.

Change 2991016 on 2016/05/26 by Steve.Robb

	Static analysis fixes:

	warning C6236: (<expression> || <non-zero constant>) is always a non-zero constant.

Change 2991017 on 2016/05/26 by Steve.Robb

	Static analysis fixes:

	warning C6326: Potential comparison of a constant with another constant.

Change 2991019 on 2016/05/26 by Steve.Robb

	Static analysis fixes:

	warning C6292: Ill-defined for-loop:  counts up from maximum.

Change 2991023 on 2016/05/26 by Steve.Robb

	Static analysis fixes:

	warning C6322: Empty _except block.
	warning C28251: Inconsistent annotation for 'WinMain': this instance has no annotations.

Change 2991070 on 2016/05/26 by Steve.Robb

	Static analysis fixes:

	warning C28182: Dereferencing NULL pointer. 'Ptr1' contains the same NULL value as 'Ptr2' did.

Change 2991416 on 2016/05/26 by Steve.Robb

	Static analysis fixes:

	warning C6011: Dereferencing NULL pointer 'Ptr'.

Change 2992738 on 2016/05/27 by Steve.Robb

	Revert changes to FString::MatchesWildcard.

Change 2992916 on 2016/05/27 by Steve.Robb

	Static analysis fixes:

	warning C6011: Dereferencing NULL pointer 'Ptr'.

Change 2992960 on 2016/05/27 by Chris.Wood

	Optimized P4 access in Crash Report Process and MinidumpDiagostics.

Change 2992964 on 2016/05/27 by Steve.Robb

	Static analysis fixes:

	warning C6011: Dereferencing NULL pointer 'Ptr'.

Change 2993956 on 2016/05/30 by Robert.Manuszewski

	Fixing a crash after adding a new C++ class in the editor - made sure new classes have the token stream assembled after hot-reload.

	#jira UE-31309

Change 2993977 on 2016/05/30 by Robert.Manuszewski

	Don't wait for all packages to finish loading before PostLoading those which already have.

Change 2994206 on 2016/05/31 by Robert.Manuszewski

	PR #2429: Three bug fixes required for script support to work properly (Contributed by pluranium)

#lockdown Nick.Penwarden

[CL 2996251 by Robert Manuszewski in Main branch]
2016-06-01 12:08:56 -04:00

130 lines
4.0 KiB
C#

// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Text;
namespace Tools.DotNETCommon.SimpleWebRequest
{
/// <summary>
/// A class to make simple Xml web requests to return a string.
/// </summary>
public class SimpleWebRequest
{
/// <summary>
/// Default constructor.
/// </summary>
public SimpleWebRequest()
{
}
/// <summary>
/// Create an HttpWebRequest with an optional Xml payload.
/// </summary>
/// <param name="WebRequestString">The URL and parameters of the web request.</param>
/// <param name="Payload">The Xml data to attached to request, or null.</param>
/// <param name="Timeout">Timeout in millisec</param>
/// <returns>A valid HttpWebRequest, or null for any failure.</returns>
/// <remarks>This uses the POST method with default credentials and a content type of 'text/xml'.</remarks>
static public HttpWebRequest CreateWebRequest(string WebRequestString, string Payload, int Timeout = 100000)
{
HttpWebRequest Request = null;
try
{
Request = ( HttpWebRequest )WebRequest.Create( WebRequestString );
Request.Method = "POST";
Request.UseDefaultCredentials = true;
Request.SendChunked = false;
Request.Timeout = Timeout;
if( Payload != null )
{
byte[] Buffer = Encoding.UTF8.GetBytes( Payload );
Request.ContentType = "text/xml";
Request.ContentLength = Buffer.Length;
using (Stream RequestStream = Request.GetRequestStream())
{
RequestStream.Write(Buffer, 0, Buffer.Length);
}
}
else
{
Request.ContentLength = 0;
}
}
catch( Exception Ex )
{
Debug.WriteLine( "Exception in CreateRequest: " + Ex.Message );
Request = null;
}
return Request;
}
/// <summary>
/// Get a string response from an HttpWebRequest.
/// </summary>
/// <param name="Request">A valid HttpWebRequest.</param>
/// <returns>The string returned from the web request, or an empty string if there was an error.</returns>
/// <remarks>The response status code needs to be 'OK' for results to be processed. Also, this is designed for simple queries,
/// so there is an arbitrary 1024 byte limit to the response size.</remarks>
static public string GetWebResponse( HttpWebRequest Request )
{
string ResponseString = "";
try
{
using (HttpWebResponse WebResponse = (HttpWebResponse)Request.GetResponse())
{
// Simple size check to prevent exploits
if (WebResponse.StatusCode == HttpStatusCode.OK && WebResponse.ContentLength < 4096)
{
// Process the response
using (Stream ResponseStream = WebResponse.GetResponseStream())
{
byte[] RawResponse = new byte[WebResponse.ContentLength];
ResponseStream.Read(RawResponse, 0, (int)WebResponse.ContentLength);
ResponseStream.Close();
ResponseString = Encoding.UTF8.GetString(RawResponse);
}
}
}
}
catch( Exception Ex )
{
Debug.WriteLine( "Exception in GetWebResponse: " + Ex.Message );
ResponseString = "";
}
return ResponseString;
}
/// <summary>
/// Send a web request to a web service and return a response string.
/// </summary>
/// <param name="WebRequestString">The URL of the request with parameters.</param>
/// <param name="Payload">The Xml payload of the request (can be null).</param>
/// <param name="Timeout">Timeout in millisec</param>
/// <returns>A string returned from the web request, or an empty string if there was any error.</returns>
/// <remarks>This calls CreateWebRequest and GetWebResponse internally.</remarks>
static public string GetWebServiceResponse( string WebRequestString, string Payload, int Timeout = 100000)
{
string ResponseString = "";
if( WebRequestString != null )
{
HttpWebRequest Request = CreateWebRequest(WebRequestString, Payload, Timeout);
if( Request != null )
{
ResponseString = GetWebResponse( Request );
}
}
return ResponseString;
}
}
}