Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,25 @@ namespace {{packageName}}.Client
headers.Add(responseHeader.Key + "=" + ClientUtils.ParameterToString(responseHeader.Value));
}

// RFC 2183 & RFC 2616
var fileNameRegex = new Regex(@"Content-Disposition=.*filename=['""]?([^'""\s]+)['""]?$", RegexOptions.IgnoreCase);
if (type == typeof(byte[])) // return byte array
{
return await response.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
}
else if (type == typeof(FileParameter))
{
if (headers != null) {
foreach (var header in headers)
{
var match = fileNameRegex.Match(header.ToString());
if (match.Success)
{
string fileName = ClientUtils.SanitizeFilename(match.Groups[1].Value.Replace("\"", "").Replace("'", ""));
return new FileParameter(fileName, await response.Content.ReadAsStreamAsync().ConfigureAwait(false));
}
}
}
return new FileParameter(await response.Content.ReadAsStreamAsync().ConfigureAwait(false));
}

Expand All @@ -122,10 +135,10 @@ namespace {{packageName}}.Client
var filePath = string.IsNullOrEmpty(_configuration.TempFolderPath)
? Path.GetTempPath()
: _configuration.TempFolderPath;
var regex = new Regex(@"Content-Disposition=.*filename=['""]?([^'""\s]+)['""]?$");

foreach (var header in headers)
{
var match = regex.Match(header.ToString());
var match = fileNameRegex.Match(header.ToString());
if (match.Success)
{
string fileName = filePath + ClientUtils.SanitizeFilename(match.Groups[1].Value.Replace("\"", "").Replace("'", ""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,25 @@ internal async Task<object> Deserialize(HttpResponseMessage response, Type type)
headers.Add(responseHeader.Key + "=" + ClientUtils.ParameterToString(responseHeader.Value));
}

// RFC 2183 & RFC 2616
var fileNameRegex = new Regex(@"Content-Disposition=.*filename=['""]?([^'""\s]+)['""]?$", RegexOptions.IgnoreCase);
if (type == typeof(byte[])) // return byte array
{
return await response.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
}
else if (type == typeof(FileParameter))
{
if (headers != null) {
foreach (var header in headers)
{
var match = fileNameRegex.Match(header.ToString());
if (match.Success)
{
string fileName = ClientUtils.SanitizeFilename(match.Groups[1].Value.Replace("\"", "").Replace("'", ""));
return new FileParameter(fileName, await response.Content.ReadAsStreamAsync().ConfigureAwait(false));
}
}
}
return new FileParameter(await response.Content.ReadAsStreamAsync().ConfigureAwait(false));
}

Expand All @@ -125,10 +138,10 @@ internal async Task<object> Deserialize(HttpResponseMessage response, Type type)
var filePath = string.IsNullOrEmpty(_configuration.TempFolderPath)
? Path.GetTempPath()
: _configuration.TempFolderPath;
var regex = new Regex(@"Content-Disposition=.*filename=['""]?([^'""\s]+)['""]?$");

foreach (var header in headers)
{
var match = regex.Match(header.ToString());
var match = fileNameRegex.Match(header.ToString());
if (match.Success)
{
string fileName = filePath + ClientUtils.SanitizeFilename(match.Groups[1].Value.Replace("\"", "").Replace("'", ""));
Expand Down