feat: copy request as cURL from the context menu#942
Conversation
PR Reviewer Guide 🔍(Review updated until commit 46bca3e)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to 46bca3e Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit e883233
Suggestions up to commit 20d95b4
|
Fixes two bugs flagged in review on #942: - buildUrl left query values raw, so spaces/quotes produced a URL curl's parser rejected ("URL rejected: Malformed input"). Query keys/values are now percent-encoded, while {{template}} vars stay literal. - Bearer/Basic auth configured on the Auth tab never made it into the exported command since it only lives in request.auth, not request.headers. Both are now resolved into an Authorization header (skipped if one is already set explicitly). OAuth1/OAuth2/inherited auth need a token exchange or parent lookup, so they're left unresolved for now. Also skips form-data file fields with no path/file name to avoid emitting invalid -F 'key=@' syntax (flagged by the PR's automated review).
|
Persistent review updated to latest commit e883233 |
|
Persistent review updated to latest commit 7e0e96b |
PR Code Suggestions ✨No code suggestions found for the PR. |
|
Persistent review updated to latest commit a60f116 |
PR Code Suggestions ✨No code suggestions found for the PR. |
|
Persistent review updated to latest commit c3a6233 |
PR Code Suggestions ✨No code suggestions found for the PR. |
|
Persistent review updated to latest commit c8ebe59 |
PR Code Suggestions ✨No code suggestions found for the PR. |
Adds a Copy as cURL entry to the request context menu in the sidebar. The command is built from method, URL with active query params, active headers and the request body (text bodies are read from the body file via the existing IPC stream and skipped when the file does not exist; file bodies reference their path; active form-data fields become -F options). Values are single-quote shell-escaped and template variables stay unresolved so no secrets leak into the copied command. Success is confirmed with a toast, failures go through the error handler. Closes #941 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Fixes two bugs flagged in review on #942: - buildUrl left query values raw, so spaces/quotes produced a URL curl's parser rejected ("URL rejected: Malformed input"). Query keys/values are now percent-encoded, while {{template}} vars stay literal. - Bearer/Basic auth configured on the Auth tab never made it into the exported command since it only lives in request.auth, not request.headers. Both are now resolved into an Authorization header (skipped if one is already set explicitly). OAuth1/OAuth2/inherited auth need a token exchange or parent lookup, so they're left unresolved for now. Also skips form-data file fields with no path/file name to avoid emitting invalid -F 'key=@' syntax (flagged by the PR's automated review).
c8ebe59 to
46bca3e
Compare
|
Persistent review updated to latest commit 46bca3e |
User description
Changes
Implements #941 — a lightweight "Copy as cURL" in the request context menu (Rename / Copy / Copy as cURL / Delete).
src/renderer/util/curl-util.ts— pure command builder:curl -X <METHOD> '<url>'with the URL built via the existingbuildUrl(active query params only).-H 'Key: value'per active header.--data-raw, plusContent-Typefrom the body mime type when no explicit header is set; file body →--data-binary @path; form-data →-Fper active field.'→'\''), parts joined with\line continuations.{{...}}) stay unresolved — portable command, no leaked secrets.RequestDropdown— new menu item; text bodies are read from the request body file via the existingIpcPushStream(requests that were never opened have no body file — the read failure is swallowed and the command is copied without a data flag). Success shows a toast, failures go through the shared error handler.Closes #941
Testing
yarn test: 444 passed — 10 new unit tests for the command builder (escaping, active-only headers/query params, all three body types, content-type handling) and 3 component tests for the menu action (body from file, missing body file, clipboard failure).yarn lint/yarn prettier-check: clean.userEvent.setup()installs its own clipboard stub, so the component tests overridenavigator.clipboardafter setup.Checklist
🤖 Generated with Claude Code
PR Type
Enhancement
Description
Adds "Copy as cURL" context menu item for quick command export
Builds cURL commands with method, URL, active headers, and body
Resolves template variables and auth configuration into commands
Handles text, file, and form-data body types with proper escaping
Includes comprehensive unit tests for command builder and UI integration
Diagram Walkthrough
File Walkthrough
5 files
Core cURL command builder with variable resolutionAdd "Copy as cURL" menu item and handlerExpose setVariablesInString method for variable resolutionImplement setVariablesInString delegation to environment serviceAdd setVariablesInString interface definition3 files
Comprehensive tests for cURL command generationTests for cURL copy menu action and clipboard integrationTest setVariablesInString method delegation