-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement support for HTTP file download for SendHttpRequest and Writ…
…eHttpResponse
- Loading branch information
1 parent
c6a32d4
commit ebaeabb
Showing
23 changed files
with
170 additions
and
124 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
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 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 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
15 changes: 0 additions & 15 deletions
15
src/activities/Elsa.Activities.Http/Parsers/DefaultHttpResponseBodyParser.cs
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
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions
14
src/activities/Elsa.Activities.Http/Parsers/Response/DefaultHttpResponseContentReader.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,14 @@ | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Elsa.Activities.Http.Services; | ||
|
||
namespace Elsa.Activities.Http.Parsers.Response | ||
{ | ||
public class DefaultHttpResponseContentReader : IHttpResponseContentReader | ||
{ | ||
public int Priority => -1; | ||
public bool GetSupportsContentType(string contentType) => true; | ||
public async Task<object> ReadAsync(HttpResponseMessage response, CancellationToken cancellationToken) => await response.Content.ReadAsStringAsync(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/activities/Elsa.Activities.Http/Parsers/Response/FileResponseContentReader.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,21 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Elsa.Activities.Http.Services; | ||
|
||
namespace Elsa.Activities.Http.Parsers.Response | ||
{ | ||
public class FileResponseContentReader : IHttpResponseContentReader | ||
{ | ||
public virtual int Priority => 5; | ||
public virtual bool GetSupportsContentType(string contentType) | ||
{ | ||
var types = new[] { "audio", "video", "application", "pdf" }; | ||
return types.Any(x => contentType.Contains(x, StringComparison.OrdinalIgnoreCase)); | ||
} | ||
|
||
public async Task<object> ReadAsync(HttpResponseMessage response, CancellationToken cancellationToken) => await response.Content.ReadAsByteArrayAsync(); | ||
} | ||
} |
12 changes: 6 additions & 6 deletions
12
...ttp/Parsers/JsonHttpResponseBodyParser.cs → ...Response/JsonHttpResponseContentReader.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
14 changes: 0 additions & 14 deletions
14
src/activities/Elsa.Activities.Http/Services/IHttpResponseBodyParser.cs
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
src/activities/Elsa.Activities.Http/Services/IHttpResponseContentReader.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,13 @@ | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Elsa.Activities.Http.Services | ||
{ | ||
public interface IHttpResponseContentReader | ||
{ | ||
int Priority { get; } | ||
bool GetSupportsContentType(string contentType); | ||
Task<object> ReadAsync(HttpResponseMessage response, CancellationToken cancellationToken); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/scripting/Elsa.Scripting.JavaScript/Converters/Jint/ByteArrayConverter.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,24 @@ | ||
using Jint; | ||
using Jint.Native; | ||
using Jint.Runtime.Interop; | ||
|
||
namespace Elsa.Scripting.JavaScript.Converters.Jint | ||
{ | ||
/// <summary> | ||
/// Prevents Jint from returning byte[] as object[]. | ||
/// </summary> | ||
internal class ByteArrayConverter : IObjectConverter | ||
{ | ||
public bool TryConvert(Engine engine, object value, out JsValue result) | ||
{ | ||
result = JsValue.Null; | ||
|
||
if (value is not byte[] buffer) | ||
return false; | ||
|
||
result = new ObjectWrapper(engine, buffer); | ||
|
||
return true; | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...nverters/TruncatingNumberJsonConverter.cs → ...ers/Json/TruncatingNumberJsonConverter.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
Oops, something went wrong.