Skip to content

feature: add copy-as-code-snippet for requests on the Send page#243

Open
komen205 wants to merge 1 commit into
httptoolkit:mainfrom
komen205:send-copy-as-code-snippet
Open

feature: add copy-as-code-snippet for requests on the Send page#243
komen205 wants to merge 1 commit into
httptoolkit:mainfrom
komen205:send-copy-as-code-snippet

Conversation

@komen205

Copy link
Copy Markdown

What

Adds the ability to copy a request as a code snippet directly from the Send page, while editing it — without having to send it first and export from the View page.

A new copy button sits in the Send request line (between the URL input and the Send button). Clicking it opens a menu mirroring the View page's export context menu:

  • "Copy as X Snippet" shortcut for the preferred format, when one is set
  • A "Copy as Code Snippet" submenu with all available httpsnippet targets

Picking a format from the submenu copies the snippet and updates the persisted preferred format (uiStore.exportSnippetFormat), same as the View page behaviour.

How

  • generateHarRequestFromRequestData() in har.ts builds an ExtendedHarRequest from not-yet-sent request data (decoded body, raw headers, HTTP/1.1), reusing the existing cookie parsing, postData generation, and non-UTF8 body fallback.
  • generateCodeSnippetFromRequestInput() in export.ts feeds that through the same HAR-simplification + httpsnippet conversion as the existing View-page path, which was refactored into a shared helper so both stay in sync (content-length/content-encoding/H2 pseudo-header dropping etc).
  • Snippet options are Pro-gated, matching the View page's export menu.
  • Invalid in-progress URLs fail with an alert rather than copying a broken snippet, and the button is disabled while the URL is empty.

Tests

Added test/unit/model/ui/export.spec.ts covering snippet generation from request inputs: simple GET, POST with body (content-length dropped), content-encoding dropped with decoded body used, and a clear failure for invalid URLs. Full unit suite passes (894 tests).

🤖 Generated with Claude Code

Adds a copy button to the Send request line that opens a menu of code
snippet formats, mirroring the View page's export context menu. The
snippet is generated directly from the in-progress request input, so
requests can be exported as code while editing, before they're sent.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@komen205

komen205 commented Jun 11, 2026

Copy link
Copy Markdown
Author

Looks like this
image

CURL *hnd = curl_easy_init();

curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(hnd, CURLOPT_URL, "http://android.httptoolkit.tech/config");

struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Host: android.httptoolkit.tech");
headers = curl_slist_append(headers, "Connection: Keep-Alive");
headers = curl_slist_append(headers, "Accept-Encoding: gzip");
headers = curl_slist_append(headers, "User-Agent: okhttp/4.11.0");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);

curl_easy_setopt(hnd, CURLOPT_ACCEPT_ENCODING, "");

CURLcode ret = curl_easy_perform(hnd);

@komen205 komen205 changed the title Add copy-as-code-snippet for requests on the Send page feature: add copy-as-code-snippet for requests on the Send page Jun 11, 2026
: undefined;

const menuItems: Array<ContextMenuItem<void>> = [
...(!isPaidUser ? [

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is worth to keep, the whole feature is already gated anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant