Skip to content

Commit 933b72e

Browse files
Mariana Dematterainersigwald
authored andcommitted
Merged PR 627361: [vs17.11] DownloadFile should not rely on the response headers
DownloadFile should not rely on the remote server response headers. Unless the DestinationFileName task parameter is specified - let's just fallback to the request URI - which is as well the publicly documented behavior ---- #### AI description (iteration 1) #### PR Classification Bug fix to ensure `DownloadFile` does not rely on response headers for file name determination. #### PR Summary This pull request modifies the `DownloadFile` task to avoid using response headers for determining the file name, instead relying on the request URI. - Changes in `src/Tasks/DownloadFile.cs` to use `requestUri` instead of `response` for file name extraction. - Updated method signature and logic in `TryGetFileName` to handle `requestUri`. <!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
1 parent e8f3d27 commit 933b72e

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

eng/Versions.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<!-- 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. -->
33
<Project>
44
<PropertyGroup>
5-
<VersionPrefix>17.11.30</VersionPrefix>
5+
<VersionPrefix>17.11.31</VersionPrefix>
66
<DotNetFinalVersionKind>release</DotNetFinalVersionKind>
77
<PackageValidationBaselineVersion>17.10.4</PackageValidationBaselineVersion>
88
<AssemblyVersion>15.1.0.0</AssemblyVersion>

src/Tasks/DownloadFile.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ private async Task DownloadAsync(Uri uri, CancellationToken cancellationToken)
169169
#endif
170170
}
171171

172-
if (!TryGetFileName(response, out string filename))
172+
if (!TryGetFileName(uri, out string filename))
173173
{
174174
Log.LogErrorWithCodeFromResources("DownloadFile.ErrorUnknownFileName", SourceUrl, nameof(DestinationFileName));
175175
return;
@@ -308,25 +308,24 @@ private static bool IsRetriable(Exception exception, out Exception actualExcepti
308308
/// <summary>
309309
/// Attempts to get the file name to use when downloading the file.
310310
/// </summary>
311-
/// <param name="response">The <see cref="HttpResponseMessage"/> with information about the response.</param>
311+
/// <param name="requestUri">The uri we sent request to.</param>
312312
/// <param name="filename">Receives the name of the file.</param>
313313
/// <returns><code>true</code> if a file name could be determined, otherwise <code>false</code>.</returns>
314-
private bool TryGetFileName(HttpResponseMessage response, out string filename)
314+
private bool TryGetFileName(Uri requestUri, out string filename)
315315
{
316-
if (response == null)
316+
if (requestUri == null)
317317
{
318-
throw new ArgumentNullException(nameof(response));
318+
throw new ArgumentNullException(nameof(requestUri));
319319
}
320320

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

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

329-
return !String.IsNullOrWhiteSpace(filename);
328+
return !string.IsNullOrWhiteSpace(filename);
330329
}
331330

332331
#if !NET6_0_OR_GREATER

0 commit comments

Comments
 (0)