Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

com.utilities.rest 2.5.5 #71

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions Utilities.Rest/Packages/com.utilities.rest/Runtime/Rest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -1137,7 +1138,7 @@ async void CallbackThread()
}
}

#pragma warning disable CS4014 // We purposefully don't await this task so it will run on a background thread.
#pragma warning disable CS4014 // We purposefully don't await this task, so it will run on a background thread.
Task.Run(CallbackThread, cancellationToken);
#pragma warning restore CS4014
}
Expand All @@ -1146,9 +1147,39 @@ async void CallbackThread()

if (hasUpload && webRequest.uploadHandler != null)
{
requestBody = webRequest.uploadHandler.data is { Length: > 0 }
? Encoding.UTF8.GetString(webRequest.uploadHandler.data)
: string.Empty;
var contentType = webRequest.GetRequestHeader(content_type);
if (webRequest.uploadHandler.data is { Length: > 0 } &&
contentType.Contains("multipart/form-data"))
{
var boundary = contentType.Split(';')[1].Split('=')[1];
var encodedData = Encoding.UTF8.GetString(webRequest.uploadHandler.data);
var formData = encodedData.Split(new[] { $"\r\n--{boundary}\r\n", $"\r\n--{boundary}--\r\n" }, StringSplitOptions.RemoveEmptyEntries);
var formParts = new Dictionary<string, string>();

foreach (var form in formData)
{
var formFields = form.Split(new[] { "\r\n\r\n" }, StringSplitOptions.RemoveEmptyEntries);
var fieldHeader = formFields[0];
var key = fieldHeader.Split(new[] { "name=\"" }, StringSplitOptions.RemoveEmptyEntries)[1].Split("\"")[0];

if (fieldHeader.Contains("application/octet-stream"))
{
var fileName = fieldHeader.Split(new[] { "filename=\"" }, StringSplitOptions.RemoveEmptyEntries)[1].Split("\"")[0];
formParts.Add(key, fileName);
}
else
{
var value = formFields[1];
formParts.Add(key, value);
}
}

requestBody = JsonConvert.SerializeObject(new { contentType, formParts });
}
else
{
requestBody = string.Empty;
}
}

try
Expand Down
2 changes: 1 addition & 1 deletion Utilities.Rest/Packages/com.utilities.rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Utilities.Rest",
"description": "This package contains useful RESTful utilities for the Unity Game Engine.",
"keywords": [],
"version": "2.5.4",
"version": "2.5.5",
"unity": "2021.3",
"documentationUrl": "https://github.com/RageAgainstThePixel/com.utilities.rest#documentation",
"changelogUrl": "https://github.com/RageAgainstThePixel/com.utilities.rest/releases",
Expand Down
4 changes: 2 additions & 2 deletions Utilities.Rest/Packages/manifest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"dependencies": {
"com.unity.addressables": "1.21.20",
"com.unity.ide.rider": "3.0.27",
"com.unity.ide.rider": "3.0.28",
"com.unity.ide.visualstudio": "2.0.22",
"com.utilities.buildpipeline": "1.2.2"
"com.utilities.buildpipeline": "1.3.0"
},
"scopedRegistries": [
{
Expand Down