Skip to content

Add advanced copy with content-type conversion - #7

Draft
tomek7667 with Copilot wants to merge 8 commits into
masterfrom
copilot/add-advanced-copy-tooltip
Draft

tomek7667 with Copilot wants to merge 8 commits into
masterfrom
copilot/add-advanced-copy-tooltip

Conversation

Copilot AI commented Jan 5, 2026 •

Copy link
Copy Markdown
Contributor

Adds "Advanced..." menu option to convert request bodies between content-types (JSON, form-urlencoded, and multipart) while automatically updating the Content-Type header.

Changes

  • Content-type converter (content_type_converter.py)

    • Bidirectional conversion between application/json, application/x-www-form-urlencoded, and multipart/form-data
    • URL encoding/decoding with bounds checking
    • Simplified _from_dict method to remove redundant conditional branches
  • RequestTree enhancement (request_tree.py)

    • Added optional target_content_type parameter
    • Automatic body conversion and header update when target differs from source
    • Support for multipart/form-data conversions
    • Fixed bounds checking in _url_decode to prevent IndexError on malformed input
  • UI addition (main.py)

    • "Advanced..." menu item in "more..." submenu
    • Dialog format: <content-type-number>,<language> (e.g., 1,js or 2,python)
    • Error handling for invalid input
    • SUPPORTED_LANGUAGES constant for centralized language configuration
  • Tests

    • 8 tests for content-type converter (including multipart support)
    • 3 tests for RequestTree conversion
    • 4 integration tests covering JS/Python × JSON/form combinations

Usage

Right-click request → Extensions > Copy Request > more > Advanced...
Enter: 2,js (converts to form-urlencoded, outputs JavaScript)
Enter: 3,python (converts to multipart, outputs Python)

Original JSON request:

{"username": "test", "password": "secret"}

Generates code with converted body and updated header:

// Content-Type: application/x-www-form-urlencoded
const stringifiedBody = constructXWwwFormUrlencoded(body);
Original prompt

This section details on the original issue you should resolve

<issue_title>idea: advanced copy tooltip</issue_title>
<issue_description>add additional Copy as field Advanced... which will include an option to copy a request as other content-type than the original request. Idea from bun ctf challenge.</issue_description>

Comments on the Issue (you are @copilot in this section)

@tomek7667 consideration: this should also change the content-type header accordingly

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 5 commits January 5, 2026 14:03
Co-authored-by: tomek7667 <38402753+tomek7667@users.noreply.github.com>
Co-authored-by: tomek7667 <38402753+tomek7667@users.noreply.github.com>
Co-authored-by: tomek7667 <38402753+tomek7667@users.noreply.github.com>
Co-authored-by: tomek7667 <38402753+tomek7667@users.noreply.github.com>
Co-authored-by: tomek7667 <38402753+tomek7667@users.noreply.github.com>
Copilot AI changed the title [WIP] Add advanced copy tooltip for different content types Add advanced copy with content-type conversion Jan 5, 2026
Copilot AI requested a review from tomek7667 January 5, 2026 14:12
Comment thread ADVANCED_COPY_EXAMPLES.md Outdated

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

remove this file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed in b54e767

Comment thread IMPLEMENTATION_SUMMARY.md Outdated

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

remove this file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed in b54e767

Comment thread README.md
- **as python requests (custom filtering)** - Python implementation with custom header filtering
- **Advanced...** - Convert request to a different content-type and language

## Advanced Copy Feature

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

make this much shorter paragraph will be sufficient

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Simplified to a single paragraph in b54e767

Comment thread content_type_converter.py Outdated
def _from_dict(data_dict, content_type):
"""Convert dictionary to target content type format."""
if content_type == "application/json":
return data_dict

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

all these ifs return the sama data_dict...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed - simplified to return data_dict directly since all formats use dict internally in b54e767

Comment thread content_type_converter.py
class ContentTypeConverter:
"""
Converts request body data between different content types.
Supports conversions between:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

That's bad. Multipart should be supported too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added multipart/form-data support in b54e767

Comment thread main.py Outdated
if content_type_index < 0 or content_type_index >= len(supported_types):
raise ValueError("Invalid content type selection")

if language not in ['js', 'python']:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

If you need supported langs, dont hardcode, make them globally available from one place and access from it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added SUPPORTED_LANGUAGES constant at module level in b54e767

Copilot AI and others added 2 commits January 8, 2026 19:31
…ort, use constant for languages

Co-authored-by: tomek7667 <38402753+tomek7667@users.noreply.github.com>
Co-authored-by: tomek7667 <38402753+tomek7667@users.noreply.github.com>
Copilot AI requested a review from tomek7667 January 8, 2026 19:34
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.

idea: advanced copy tooltip

2 participants