| | | 1 | | using Elsa.Extensions; |
| | | 2 | | using Elsa.Http.Contexts; |
| | | 3 | | |
| | | 4 | | namespace Elsa.Http.Parsers; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Reads received file from the HTTP response, if any. |
| | | 8 | | /// </summary> |
| | | 9 | | public class FileHttpContentParser : IHttpContentParser |
| | | 10 | | { |
| | | 11 | | /// <inheritdoc /> |
| | | 12 | | // Lower priority than other parsers, so that they can be tried first. |
| | | 13 | | // If none of them can parse the content, this parser will be tried and interpret the content as a file. |
| | 206 | 14 | | public int Priority => -100; |
| | | 15 | | |
| | | 16 | | /// <inheritdoc /> |
| | | 17 | | public bool GetSupportsContentType(HttpResponseParserContext context) |
| | | 18 | | { |
| | 0 | 19 | | return true; |
| | | 20 | | } |
| | | 21 | | |
| | | 22 | | /// <inheritdoc /> |
| | | 23 | | public Task<object> ReadAsync(HttpResponseParserContext context) |
| | | 24 | | { |
| | 0 | 25 | | var stream = context.Content; |
| | 0 | 26 | | var filename = context.Headers.GetFilename() ?? "file.dat"; |
| | 0 | 27 | | var contentType = context.ContentType; |
| | 0 | 28 | | context.Headers.TryGetValue("ETag", out var eTag); |
| | 0 | 29 | | var file = new HttpFile(stream, filename, contentType, eTag?.FirstOrDefault()); |
| | 0 | 30 | | return Task.FromResult<object>(file); |
| | | 31 | | } |
| | | 32 | | } |