amingolmahalle / HttpClientToCurlGenerator

The HttpClientToCurl is a NuGet package for generating curl script of HttpClient in .NET ( C# | CSharp | Dotnet ) supported features: Post, Get, Put, and Delete. content types: application/json, text/xml, application/x-www-form-urlencoded
https://www.nuget.org/packages/HttpClientToCurl
MIT License
51 stars 11 forks source link

Add cURL compressed command-line option #24

Closed kokoabim closed 4 months ago

kokoabim commented 6 months ago

Add the cURL --compressed command-line option to the outputted command-line by default. Most requests nowadays have compression encoding, i.e. the header Accept-Encoding: gzip; deflate; br.

amingolmahalle commented 6 months ago

Thank you dear @kokoabim I will check it.

amingolmahalle commented 5 months ago

Thank you dear @kokoabim for your attention to this issue. I found, that the --compressed option is equivalent to adding the header Accept-Encoding: deflate, gzip, br to the request, which tells the server that the client can accept compressed data. The server can then choose one of the algorithms and send the compressed data with the header Content-Encoding: to indicate the compression method. Curl will then automatically decompress the data and save the uncompressed document. This can reduce the amount of data transferred and improve the performance of the script. However, the server must support the compression algorithms that curl supports, such as deflate or gzip. This will request a compressed response from the server and save the uncompressed document. If the server does not support compression or sends an unsupported encoding, curl will report an error. In my opinion, It's better programmer to specify this option itself. we do not automatically add this option to the curl script. because we are just a curl script generator. What is your opinion now?

kokoabim commented 5 months ago

I believe having on be default is convenient. I've seen cURL not decompress even with your referenced header. I see it many times. Having it on by default won't "hurt".

naeemaei commented 5 months ago

@kokoabim @amingolmahalle We must note that this package has the task of converting HttpClientto CURL and should create exactly what the user client needs, even if the HTTP request has a problem. I suggest that this item be added to the input option and the user can specify it.

amingolmahalle commented 5 months ago

@kokoabim @amingolmahalle We must note that this package has the task of converting HttpClientto CURL and should create exactly what the user client needs, even if the HTTP request has a problem. I suggest that this item be added to the input option and the user can specify it.

@naeemaei I agree with you. adding this ability as an input option is a great idea. @kokoabim What Do you think?

kokoabim commented 5 months ago

I'm unfamiliar with the input options myself. Just as long as it's enabled it's fine. the code could be modified to autodetect the encoding and add the option regardless of input on the users end. I noticed the need as most the queries I use it for requires the switch. Either was is fine.

kokoabim commented 5 months ago

I've just in the past cloned the repository and modify the code myself. I had once or twice submitted a PR but was denied because I didn't have permission.

kokoabim commented 5 months ago

another thing that would be nice but it will not work on windows which it only works on linux and macOS is that after each command argument having a backwack ("\") and new line after it, so it's easier to read in the terminal but again for a windows user I don't think that that supported.

amingolmahalle commented 5 months ago

I'm unfamiliar with the input options myself. Just as long as it's enabled it's fine. the code could be modified to autodetect the encoding and add the option regardless of input on the users end. I noticed the need as most the queries I use it for requires the switch. Either was is fine.

The code below is a sample with option input. with the last of parameters, you can set configs for results to fit with the result type that you want to take. (Result type means: Put it in a string variable, Show to the IDE console, or Write in a file) For example, we can add config.CompressEnabled=true; to options.if the developer likes this config he/she can only set this option in the input config.

httpClient.GenerateCurlInConsole(
    httpRequestMessage,
    config =>
    {
        config.TurnOn = true;
        config.NeedAddDefaultHeaders = true;
        config.EnableCodeBeautification = false;
    });
amingolmahalle commented 5 months ago

I've just in the past cloned the repository and modify the code myself. I had once or twice submitted a PR but was denied because I didn't have permission.

I haven't realized your problem with cloning the repository. If you get a fork of this repository then you can send your merge request. the pull request is open for all.

amingolmahalle commented 5 months ago

another thing that would be nice but it will not work on windows which it only works on linux and macOS is that after each command argument having a backwack ("") and new line after it, so it's easier to read in the terminal but again for a windows user I don't think that that supported.

We must have changes that all operation systems support dear @kokoabim.Our main aim is to keep all developers happy. :)

amingolmahalle commented 4 months ago

closed