-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix UnityWebRequestHttpMessageHandler
- Loading branch information
1 parent
3f37d8c
commit 221ca9b
Showing
14 changed files
with
155 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using System.Collections; | ||
using System.Net.Http; | ||
using NUnit.Framework; | ||
using UnityEngine.TestTools; | ||
|
||
namespace MinimalUtility.Test | ||
{ | ||
using WebRequest; | ||
using TestUtils = MinimalUtility.Editor.TestUtils; | ||
|
||
public class MinimalTest | ||
{ | ||
[UnityTest, Order(0), Timeout(300000)] | ||
public IEnumerator WebRequestTest() | ||
{ | ||
#if ENABLE_UNITASK | ||
return Cysharp.Threading.Tasks.UniTask.ToCoroutine(async () => | ||
{ | ||
const string uri = "https://httpbin.org/post"; | ||
|
||
using var client = new HttpClient(new UnityWebRequestHttpMessageHandler()); | ||
using var request = new HttpRequestMessage(HttpMethod.Post, uri) | ||
{ | ||
Content = new ByteArrayContent(new byte[] {1, 2, 3, 4, 5}) | ||
{ | ||
Headers = | ||
{ | ||
ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json") | ||
} | ||
} | ||
}; | ||
using var response = await client.SendAsync(request); | ||
await TestContext.Out.WriteLineAsync(await response.Content.ReadAsStringAsync()); | ||
}); | ||
#else | ||
yield break; | ||
#endif | ||
} | ||
|
||
|
||
[UnityTest, Order(1), Timeout(300000)] | ||
public IEnumerator UniTaskPackageRemoveTest() | ||
{ | ||
yield return PackageRemoveTest("com.cysharp.unitask"); | ||
Assert.Pass(); | ||
} | ||
|
||
[UnityTest, Order(2), Timeout(300000)] | ||
public IEnumerator R3PackageRemoveTest() | ||
{ | ||
yield return PackageRemoveTest("com.cysharp.r3"); | ||
Assert.Pass(); | ||
} | ||
|
||
[UnityTest, Order(3), Timeout(300000)] | ||
public IEnumerator VContainerPackageRemoveTest() | ||
{ | ||
yield return PackageRemoveTest("jp.hadashikick.vcontainer"); | ||
Assert.Pass(); | ||
} | ||
|
||
[UnityTest, Order(4), Timeout(300000)] | ||
public IEnumerator UGUIPackageRemoveTest() | ||
{ | ||
yield return PackageRemoveTest("com.unity.ugui"); | ||
Assert.Pass(); | ||
} | ||
|
||
[Test, Order(5)] | ||
public void CompileCheckTest() | ||
{ | ||
var result = TestUtils.SuccessCompile(UnityEditor.BuildTarget.StandaloneOSX); | ||
Assert.IsTrue(result); | ||
} | ||
|
||
private static IEnumerator PackageRemoveTest(string packageName) | ||
{ | ||
var request = UnityEditor.PackageManager.Client.Remove(packageName); | ||
while (!request.IsCompleted) | ||
{ | ||
yield return null; | ||
} | ||
if (request.Status != UnityEditor.PackageManager.StatusCode.Success) | ||
{ | ||
throw new System.Exception("Failed to remove package: " + packageName); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
56 changes: 0 additions & 56 deletions
56
Packages/MinimalUtility/Runtime/Tasks/UniTaskExtensions.cs
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
Packages/MinimalUtility/Runtime/Tasks/UniTaskExtensions.cs.meta
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
Packages/MinimalUtility/Runtime/WebRequest/NativeArrayContent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using System.IO; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Unity.Collections; | ||
|
||
namespace MinimalUtility.WebRequest | ||
{ | ||
/// <summary> | ||
/// <see cref="NativeArray{T}"/>を基盤とする<see cref="HttpContent"/>. | ||
/// </summary> | ||
public sealed class NativeArrayContent : HttpContent | ||
{ | ||
private readonly NativeArray<byte>.ReadOnly _data; | ||
private readonly IDisposable _handler; | ||
|
||
public NativeArrayContent(NativeArray<byte>.ReadOnly data, IDisposable handler) | ||
{ | ||
_data = data; | ||
_handler = handler; | ||
} | ||
|
||
protected override Task SerializeToStreamAsync(Stream stream, TransportContext _) | ||
{ | ||
stream.Write(_data.AsReadOnlySpan()); | ||
return Task.CompletedTask; | ||
} | ||
|
||
protected override bool TryComputeLength(out long length) | ||
{ | ||
length = _data.Length; | ||
return true; | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
if (disposing) | ||
{ | ||
_handler.Dispose(); | ||
} | ||
base.Dispose(disposing); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Packages/MinimalUtility/Runtime/WebRequest/NativeArrayContent.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.