Add action to save response body to file #192
Merged
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.
Description
Describe the change. If there is an associated issue, please include the issue link (e.g. "Closes #xxx"). For UI changes, please also include screenshots.
Closes #183
Adds a new action "Save Body as File" to the response pane. The content to be saved has three possible values:
Once the content to be saved is determined, it will prompt the user for a file name to save as. We'll try to figure out a default file name according to these steps:
Content-Disposition
header for afilename="<value>"
parameter. If present, use<value>
Content-Type
header to get the extension from the content subtype (e.g.json
fromapplication/json
, orpng
fromimage/png
). The file name will bedata.<extension>
Content-Type
header is missing or invalid (extremely uncommon), provide no defaultOnce we have a file name, we can join it with the current working directory to get a path. Then we try to save to that file. If the file already exists, we'll prompt the user with a yes/no confirmation to make sure they want to overwrite it.
Known Risks
What issues could potentially go wrong with this change? Is it a breaking change? What have you done to mitigate any potential risks?
The behavior described above is a bit complex, which introduces room both for bugs and surprising behaviors. For example, users might be surprised that if they have JSON query applied, it will save the query result rather than the full file. I think it's fairly intuitive to save what you see, and that's also how the "Copy Body" action works so it's consistent at least. I wouldn't be surprised if we get some issues filed about this in the future. To mitigate the bug issue, I'll be adding tests.
There's potential risk around the handling of file paths, e.g. path traversal. I didn't do any handling here, instead leaning on the OS/file system to protect itself. Since this is a client-side app, we don't have to worry about people overwriting system files etc. that they don't have access to. It's possible a user could accidentally overwrite an existing file, which is mitigated with the "This file already exists" confirmation.
QA
How did you test this?
Just manually tested for now. I really want to add unit tests but we don't have any established for the UI yet, so I need to figure out some patterns for that. Working on it now.
Checklist
CONTRIBUTING.md
already?CHANGELOG.md
?