Feature/copy log as curl (#1458)#1683
Conversation
|
FYI: It's still needed to create some test coverage related to other methods and probably fix the existing ones (unfortunately I'm having a bad time testing on Manjaro). With that, said there's still work to be done. |
|
Hello, @255kb! I was thinking to add a new context menu when it's a proxied request to the user be able to copy either the Mockoon request or the proxied request made by Mockoon. What are your thoughts on that? I'd also like to hear your concerns about changing the http utils with the default value as {}. In my perspective I could remove this default {} to have more reliability of unit tests, assuring the body is sent only when requested. Context: https://github.com/mockoon/mockoon/blob/main/packages/desktop/test/libs/http.ts#L102 |
Could you provide an example of the difference between the two? I guess it would be the URL? My first reaction: is it really useful to copy a CURL command that is not pointing to the Mockoon instance?
Feel free to improve this util. It is quite old! Just make sure that it's still working for all the other tests (obviously ;) ). |
|
@Mavbraz tried it, works well. One suggestion: We should add |
26047ea to
4900229
Compare
|
@regalstreak that's a good suggestion, but there're many compression types not mentioned. e.g: br and zstd. I agree it should have a setting to configure its use and IMO it should be true by default. What are your thoughts on that matter? |
|
@regalstreak @Mavbraz Do we really need a setting for that? My understanding was that curl's @Mavbraz PR seems kind of ready. Do you think we can finalize it in the coming week or two to include it in v9.3.0? |
|
@Mavbraz Do you think you could finalize by adding the |
|
@255kb, I think this could be a good setting, at least in my case. Sometimes I need to copy the request and the allowed compression algorithms exactly. |
|
I'll rebase this branch and push all my changes soon. Probably, it'll be possible to move with the review soon and make it to next release. |
397869f to
2399b1b
Compare
Thank you for updating the PR! I still don't see why we would need a setting. The curl command should replicate the request, if it had an accept encoding header it should include the compression flag, if not it shouldn't. Isn't it too complicated to change the setting instead of just removing the compression flag from the copied command if needed? |
a68a675 to
832f68f
Compare
|
It was rethinking about this setting and indeed it was not much valuable as I though. |
There was a problem hiding this comment.
Pull Request Overview
This PR adds the ability to copy environment logs as cURL commands, allowing users to recreate HTTP requests from the logs directly in their terminal or command line interface.
- Adds a "Copy as cURL" action to the environment logs dropdown menu
- Implements cURL command generation with proper handling of headers, request body, and compression settings
- Adds comprehensive test coverage for various scenarios including compression handling and different request types
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/app/test/specs/environment-logs.spec.ts | Adds multiple test cases validating cURL command generation for different scenarios (with/without compression, various headers, query parameters) |
| packages/app/test/libs/utils.ts | Adds COPY_AS_CURL enum value to DropdownMenuLogsActions |
| packages/app/test/libs/http.ts | Refactors body handling to support empty string bodies in HTTP calls |
| packages/app/test/libs/environments-logs.ts | Adds helper method to click the "Copy as cURL" button in tests |
| packages/app/src/renderer/app/services/environments.service.ts | Implements core cURL command generation logic with compression detection and header filtering |
| packages/app/src/renderer/app/services/data.service.ts | Adds bodyUnformatted field to preserve original request body |
| packages/app/src/renderer/app/models/environment-logs.model.ts | Adds bodyUnformatted property to EnvironmentLogRequest model |
| packages/app/src/renderer/app/components/environment-logs/environment-logs.component.ts | Adds "Copy as cURL" menu item to the logs dropdown |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
Thanks for the update! Btw, I ran the CI and some tests are not passing. |
7c5d4a1 to
687c63b
Compare
|
This latest commit I updated some models to get the original headers sent, I also fixed the failing tests and refactored the command logic to use a builder as it would give much better readability and maintainability. That said, I think now it's good to go with the reviewing, but there are just a few points I would like to discuss first:
|
Thanks for the update. I wrote some comments as part of the review. Regarding 1, sounds good. When testing I noticed that the curl command will always use localhost, even though we can now have cloud logs originating from a Update: Don't investigate the failing Windows test, it must be flaky as it's passing locally and on Linux. |
687c63b to
1003fd8
Compare
|
Is this PR going to be merged with squash commit? If not, I can do it to prevent make the main a mess. |
Yes commits will be squashed. |
There was a problem hiding this comment.
Thanks for updating the PR!
It looks good. I will see if all tests are passing and merge it. I will then add some small changes to take the cloud URLs into account, especially in the new web app where there are only cloud instance URLs.
Update: it seems tests are failing
This reverts commit 3906288.
c2ecadb to
43326f0
Compare
Thanks! I will merge and implement the Cloud logic.
If it's working with curl it's ok. We don't have to accomodate for each and every tool out there. |

Technical implementation details
Copy the log as cURL with the same headers, body and other properties was sent in the request.
Checklist
Closes #1458