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
4 changes: 2 additions & 2 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the MIT license. See License.txt in the project root for full license information. -->
<Project>
<PropertyGroup>
<VersionPrefix>17.14.7</VersionPrefix><DotNetFinalVersionKind>release</DotNetFinalVersionKind>
<VersionPrefix>17.14.8</VersionPrefix><DotNetFinalVersionKind>release</DotNetFinalVersionKind>
<PackageValidationBaselineVersion>17.13.9</PackageValidationBaselineVersion>
<AssemblyVersion>15.1.0.0</AssemblyVersion>
<PreReleaseVersionLabel>preview</PreReleaseVersionLabel>
<PreReleaseVersionLabel>servicing</PreReleaseVersionLabel>
<DotNetUseShippingVersions>true</DotNetUseShippingVersions>
<!-- Workaround for https://github.com/dotnet/roslyn/issues/35793 -->
<SemanticVersioningV1>true</SemanticVersioningV1>
Expand Down
17 changes: 8 additions & 9 deletions src/Tasks/DownloadFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private async Task DownloadAsync(Uri uri, CancellationToken cancellationToken)
#endif
}

if (!TryGetFileName(response, out string filename))
if (!TryGetFileName(uri, out string filename))
{
Log.LogErrorWithCodeFromResources("DownloadFile.ErrorUnknownFileName", SourceUrl, nameof(DestinationFileName));
return;
Expand Down Expand Up @@ -308,25 +308,24 @@ private static bool IsRetriable(Exception exception, out Exception actualExcepti
/// <summary>
/// Attempts to get the file name to use when downloading the file.
/// </summary>
/// <param name="response">The <see cref="HttpResponseMessage"/> with information about the response.</param>
/// <param name="requestUri">The uri we sent request to.</param>
/// <param name="filename">Receives the name of the file.</param>
/// <returns><code>true</code> if a file name could be determined, otherwise <code>false</code>.</returns>
private bool TryGetFileName(HttpResponseMessage response, out string filename)
private bool TryGetFileName(Uri requestUri, out string filename)
{
if (response == null)
if (requestUri == null)
{
throw new ArgumentNullException(nameof(response));
throw new ArgumentNullException(nameof(requestUri));
}

// Not all URIs contain a file name so users will have to specify one
// Example: http://www.download.com/file/1/

filename = !String.IsNullOrWhiteSpace(DestinationFileName?.ItemSpec)
filename = !string.IsNullOrWhiteSpace(DestinationFileName?.ItemSpec)
? DestinationFileName.ItemSpec // Get the file name from what the user specified
: response.Content?.Headers?.ContentDisposition?.FileName // Attempt to get the file name from the content-disposition header value
?? Path.GetFileName(response.RequestMessage.RequestUri.LocalPath); // Otherwise attempt to get a file name from the URI
: Path.GetFileName(requestUri.LocalPath); // Otherwise attempt to get a file name from the URI

return !String.IsNullOrWhiteSpace(filename);
return !string.IsNullOrWhiteSpace(filename);
}

#if !NET6_0_OR_GREATER
Expand Down