feat(http): add cURL tab to View Results Tree Request panel#6736
feat(http): add cURL tab to View Results Tree Request panel#6736poliakov-alex wants to merge 2 commits into
Conversation
Render the sampled HTTP request as a ready-to-run curl command in a new "cURL" sub-tab next to Raw and HTTP, so it can be copied to a console or shared. Closes apache#6375 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
vlsi
left a comment
There was a problem hiding this comment.
Adversarial pass over the cURL tab, on top of @milamberspace's review. I built the branch, ran the existing tests (green), and exercised buildCurlCommand with a probe test plus real curl against a local HTTP server.
The feature is worth having and the SPI integration is clean. Requesting changes for one class of problem: several ordinary samples render a command that looks correct but reproduces a different request from the one JMeter sent. Four inline notes fall into that class.
- Repeated header names are collapsed by
parseHeaders(RequestViewCurl#119). - The
X-LocalAddresspseudo-header is copied into the command although it never went on the wire (RequestViewCurl#57). HEADsamples rendercurl -X 'HEAD', which fails or hangs (RequestViewCurl#107).- Rendered-placeholder bodies reach
--data-rawon two non-multipart paths, so the multipart fix @milamberspace asked for will not cover them (RequestViewCurl#139).
The remaining notes are suggestions, not conditions.
Checked and found correct, for the record: single-quote escaping (name=O'Brien reached the server as exactly 12 bytes), -b cookie syntax, @AutoService registration (both views land in META-INF/services), message-key ordering, locale fallback through the parent bundle, and redirect handling (HTTPSamplerBase takes URL, method, headers, and body from the last hop consistently).
Render the sampled HTTP request as a ready-to-run curl command in a new "cURL" sub-tab next to Raw and HTTP, so it can be copied or shared.
Closes #6375
Description
Adds a cURL tab to the Request panel of the View Results Tree listener, next to the existing Raw and HTTP tabs. It renders the sampled HTTP request as a ready-to-run curl command that can be copied or shared.
The command includes the method (-X), the URL, request headers (-H), cookies (-b), and the request body (--data-raw). Values are single-quoted and shell-escaped so the output is paste-safe.
Connection-specific (hop-by-hop) and curl-managed headers — Connection, Keep-Alive, Proxy-Connection, Transfer-Encoding, Upgrade, Content-Length — are omitted, because reproducing them makes the request fail (e.g. Connection is forbidden in HTTP/2 and produces curl: (92) ... PROTOCOL_ERROR, and a manual Content-Length conflicts with the body curl computes).
The tab is contributed through the existing RequestView service interface (@autoservice), so no wiring changes were needed in RequestPanel.
Motivation and Context
Fixes #6375. Users frequently need to reproduce a sampled request outside JMeter — in a terminal or when handing it to a developer. Today they must reconstruct the curl command by hand from the Raw/HTTP tabs.
How Has This Been Tested?
Added RequestViewCurlTest (8 JUnit tests) covering GET, headers, POST body, header skipping, cookie handling / de-duplication, single-quote escaping, and a null URL.
Ran ./gradlew :src:protocol:http:test, checkstyleMain, checkstyleTest, autostyleJavaCheck — all green.
Manually verified in the GUI: ran an HTTP sampler, opened View Results Tree → Request → cURL, copied the command and executed it in a terminal successfully.
Screenshots (if appropriate):
Types of changes
New feature (non-breaking change which adds functionality)
Checklist: