-
Notifications
You must be signed in to change notification settings - Fork 7.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Content-Disposition for output file name in Webcmdlets #19385
Open
CarloToso
wants to merge
27
commits into
PowerShell:master
Choose a base branch
from
CarloToso:content-disposition
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
abd6e9f
content-disposition
CarloToso 612863d
add tests
CarloToso 85933ae
remove else
CarloToso 60f838b
update tests
CarloToso e27cd5f
fix writeverbose filename
CarloToso 9d3de54
reduce nesting
CarloToso 289b7f3
try fix tests
CarloToso e1e6951
try fix tests
CarloToso 76f5590
fix tests
CarloToso 7cf3850
fix bug @ImportTaste
CarloToso b278239
Update test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlet…
CarloToso 7e65367
Update test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlet…
CarloToso bcdae81
PathAndQuery
CarloToso f574f4c
qualifiedOutFile
CarloToso 13563b3
remove path and strip content-disposition
CarloToso 41ec280
add tests
CarloToso 90cb0ea
remove windows paths
CarloToso 7c4511f
Merge branch 'master' into content-disposition
CarloToso dae2b73
fix nullable
CarloToso af603b3
address wg-powershell-cmdlets review
CarloToso 6862b81
Merge branch 'master' into content-disposition
CarloToso 54e54c2
_qualifiedOutFilePath -> _qualifiedOutFile
CarloToso 700c1e4
correct test errors
CarloToso ddb3769
fix 2 tests
CarloToso 6b83431
fix typo in tests
CarloToso c4c7830
fix typo; fix QualifiedOutFile
CarloToso 6d12938
fix TabCompletion tests
CarloToso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PathAndQuery
- Loading branch information
commit bcdae81ab94f91e4f1c6a872c3ed5bd3c84ab591
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,15 +43,14 @@ internal static string GetOutFilePath(HttpResponseMessage response, string _qual | |
} | ||
|
||
string contentDisposition = response.Content.Headers.ContentDisposition?.FileNameStar ?? response.Content.Headers.ContentDisposition?.FileName; | ||
string pathAndQuery = response.RequestMessage.RequestUri.PathAndQuery; | ||
|
||
if (!string.IsNullOrEmpty(contentDisposition)) | ||
{ | ||
// Get file name from Content-Disposition header if present | ||
return Path.Join(_qualifiedOutFile, contentDisposition); | ||
} | ||
|
||
if (pathAndQuery != "/") | ||
if (response.RequestMessage.RequestUri.PathAndQuery != "/") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please clarify why we need PathAndQuery. Maybe add a comment in the code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need it to handle this case: Invoke-WebRequest https://www.google.com/ -OutFile .\ #PathAndQuery == "/"
#--> OutFile: www_google_com |
||
{ | ||
string lastUriSegment = System.Net.WebUtility.UrlDecode(response.RequestMessage.RequestUri.Segments[^1]); | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition#directives the value may have path information and should be stripped. It may or may not be enclosed in quotes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The guideline says that "filename" is usually default name for "Save As". This force we think that we go in wrong direction trying to make the cmdlet too smart. We don't really know what the user wants in a particular scenario. Therefore, I propose follow @mklement0 's proposal and introduce a new parameter AutoFileName as enum:
This way we allow the user to do exactly what he needs to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer if we left the decision to the cmdlet, if the user wants to choose a name for the file he just has to write it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope AutoFileName proposal will be discussed by WG.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SteveL-MSFT what should be the best course of action?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SteveL-MSFT any news on AutoFileName?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CarloToso sorry for the delay, I'll queue this up for discussion in Cmdlets WG