Skip to content

Commit a5b4fb9

Browse files
committed
Merge branch 'master' into release
2 parents 8242e81 + 76d4e49 commit a5b4fb9

File tree

1 file changed

+34
-11
lines changed
  • Assets/PatchKit Patcher/Scripts/AppData/Remote/WebRequestWraps

1 file changed

+34
-11
lines changed

Assets/PatchKit Patcher/Scripts/AppData/Remote/WebRequestWraps/WrapRequest.cs

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
using System.Threading;
55
using UnityEngine;
66
using PatchKit.Api;
7+
using PatchKit.Unity.Patcher.Debug;
8+
using ILogger = PatchKit.Logging.ILogger;
79

810
namespace PatchKit.Unity.Patcher.AppData.Remote
911
{
1012
public class WrapRequest : IHttpWebRequest
1113
{
14+
private static readonly DebugLogger DebugLogger = new DebugLogger(typeof(WrapRequest));
15+
1216
public const string ResponseEncoding = "iso-8859-2";
1317

1418
private readonly EventWaitHandle _waitHandle;
@@ -39,10 +43,38 @@ private IEnumerator JobCoroutine(string url)
3943
{
4044
_data = www.text;
4145

42-
if (!TryParseStatusCode(www.responseHeaders["STATUS"], out _statusCode))
46+
try
47+
{
48+
// HACK: because WWW is broken and sometimes just does not return STATUS in responseHeaders we are returning status code 200 (we can assume that status code is not an error since www.error is null or empty).
49+
if (!www.responseHeaders.ContainsKey("STATUS"))
50+
{
51+
DebugLogger.LogWarning("Response headers doesn't contain status information. Since WWW marks response as one without errors, status code is set to 200 (OK).");
52+
_statusCode = 200;
53+
}
54+
else
55+
{
56+
var status = www.responseHeaders["STATUS"];
57+
DebugLogger.Log(string.Format("Response status: {0}", status));
58+
var s = status.Split(' ');
59+
60+
if (s.Length >= 3 && int.TryParse(s[1], out _statusCode))
61+
{
62+
DebugLogger.Log(string.Format("Successfully parsed status code: {0}", _statusCode));
63+
}
64+
else
65+
{
66+
// HACK: Again, we can't parse the status code (it might be in some different format) - so we simply set it to 200.
67+
DebugLogger.LogWarning(
68+
"Unable to parse status code. Since WWW marks response as one without errors, status code is set to 200 (OK).");
69+
_statusCode = 200;
70+
}
71+
}
72+
73+
}
74+
catch (Exception e)
4375
{
4476
_wasError = true;
45-
_errorText = "Couldn't parse status code.";
77+
_errorText = e.ToString();
4678
}
4779
}
4880
else
@@ -79,14 +111,5 @@ public IHttpWebResponse GetResponse()
79111

80112
return new WrapResponse(_data, _statusCode, ResponseEncoding);
81113
}
82-
83-
private static bool TryParseStatusCode(string status, out int statusCode)
84-
{
85-
statusCode = 0;
86-
87-
var s = status.Split(' ');
88-
89-
return s.Length >= 3 && int.TryParse(s[1], out statusCode);
90-
}
91114
}
92115
}

0 commit comments

Comments
 (0)