474420502 / gcurl

parse curl bash to code of golang
11 stars 8 forks source link

request is not parsed correctly #3

Open lorypelli opened 1 month ago

lorypelli commented 1 month ago

I'm finding issues with your libraries, a lot of time parsing doesn't work and you should return an error which is usually done in go, please do this, it's a good practice to have

lorypelli commented 1 month ago

error

474420502 commented 1 month ago

@lorypelli In the earlier versions, error handling and returns were not implemented in order to quickly identify errors. However, based on your feedback, I have added error handling and returns in version v0.9.0 instead of causing panics. The error handling may not be comprehensive enough yet. If you encounter any issues, please feel free to provide feedback. Thank you for your suggestion.

lorypelli commented 1 month ago

@lorypelli In the earlier versions, error handling and returns were not implemented in order to quickly identify errors. However, based on your feedback, I have added error handling and returns in version v0.9.0 instead of causing panics. The error handling may not be comprehensive enough yet. If you encounter any issues, please feel free to provide feedback. Thank you for your suggestion.

thanks, now it gives an error in -H when pasting this:

curl "https://wails.io/assets/js/6264.be098870.js" ^
  -H "accept: */*" ^
  -H "accept-language: it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7" ^
  -H ^"cookie: ph_phc_UcoO1U6kbh3MRDXFF3Y5ycUIY15UklNky7NNhLyOupC_posthog=^%^7B^%^22distinct_id^%^22^%^3A^%^22018f1bda-30fd-7b0c-b061-76a8445efdb8^%^22^%^2C^%^22^%^24sesid^%^22^%^3A^%^5B1714940203879^%^2C^%^22018f4a66-d367-7919-b99b-bc62268a8bd2^%^22^%^2C1714940203879^%^5D^%^7D^" ^
  -H "referer: https://wails.io/docs/gettingstarted/installation" ^
  -H ^"sec-ch-ua: ^\^"Chromium^\^";v=^\^"124^\^", ^\^"Google Chrome^\^";v=^\^"124^\^", ^\^"Not-A.Brand^\^";v=^\^"99^\^"^" ^
  -H "sec-ch-ua-mobile: ?0" ^
  -H ^"sec-ch-ua-platform: ^\^"Windows^\^"^" ^
  -H "sec-fetch-dest: script" ^
  -H "sec-fetch-mode: no-cors" ^
  -H "sec-fetch-site: same-origin" ^
  -H "user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"

this is from Copy as cURL (cmd) option on chrome, same if I try with bash option

474420502 commented 1 month ago

@lorypelli Supports copying as cURL command only (Bash), I let me check and fix it.

474420502 commented 1 month ago

@lorypelli The v0.9.1 version has already addressed this issue. If you are still encountering problems, please provide the Bash command with the curl string. I can fix it, but currently, support is limited to curl commands in Bash format only; other formats are not supported at this time.

lorypelli commented 1 month ago

@lorypelli Supports copying as cURL command only (Bash), I let me check and fix it.

You should give error saying only bash is supported and not windows

474420502 commented 1 month ago

@lorypelli Supports copying as cURL command only (Bash), I let me check and fix it.

You should give error saying only bash is supported and not windows

The v0.10.0 version has already Add Parse, ParseBash, ParseCmd to make them compatible with the cmd format.

lorypelli commented 1 month ago

@lorypelli Supports copying as cURL command only (Bash), I let me check and fix it.

You should give error saying only bash is supported and not windows

The v0.10.0 version has already Add Parse, ParseBash, ParseCmd to make them compatible with the cmd format.

Thanks a lot, this is the best support I received in an issue, good...😉🙂

lorypelli commented 1 month ago

I changed the title to better understand what the issue is for other people

lorypelli commented 1 month ago

still doesn't work

lorypelli commented 1 month ago

it gives a parse error now

lorypelli commented 1 month ago
curl 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap' \
  -H 'sec-ch-ua: "Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"' \
  -H 'Referer: https://github.com/474420502/gcurl/issues/3' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "Windows"'

image

lorypelli commented 1 month ago

the alert is from an app I'm making using also your package

lorypelli commented 1 month ago

tried both with cmd and bash

474420502 commented 1 month ago

@lorypelli image I tried it and it's normal. The above curl bash can be executed smoothly.

lorypelli commented 1 month ago

@lorypelli image I tried it and it's normal. The above curl bash can be executed smoothly.

So, I'm using wrong method, I use Parse function

lorypelli commented 1 month ago

curl := gcurl.Parse(url) url is correct

474420502 commented 2 weeks ago

@lorypelli you try it v0.10.0

lorypelli commented 2 weeks ago

I'm using latest version

474420502 commented 2 weeks ago

@lorypelli

scurl := `curl 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap' \
  -H 'sec-ch-ua: "Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"' \
  -H 'Referer: https://github.com/474420502/gcurl/issues/3' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "Windows"'`
cu, err := Parse(scurl)
if err != nil {
log.Panic(err)
}
resp, err := cu.Temporary().Execute()
if err != nil {
log.Panic(err)
}

log.Println(resp.ContentString())

image

lorypelli commented 2 weeks ago

@lorypelli

scurl := `curl 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap' \
  -H 'sec-ch-ua: "Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"' \
  -H 'Referer: https://github.com/474420502/gcurl/issues/3' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "Windows"'`
cu, err := Parse(scurl)
if err != nil {
log.Panic(err)
}
resp, err := cu.Temporary().Execute()
if err != nil {
log.Panic(err)
}

log.Println(resp.ContentString())

image

https://github.com/lorypelli/FetchTTP/blob/main/app.go#L336-L372

474420502 commented 2 weeks ago

@lorypelli I think this will help image

lorypelli commented 2 weeks ago

@lorypelli I think this will help image

it adds http protocol twice, either if the url is http or https

lorypelli commented 2 weeks ago

image

lorypelli commented 2 weeks ago

and URL is not correctly parsed

lorypelli commented 2 weeks ago

ah, it's the same error as before

474420502 commented 2 weeks ago

@lorypelli The problem may stem from inadequate support for Windows. I'll consider enhancing support for Windows at a later date; I don't have the time this month.

474420502 commented 2 weeks ago

@lorypelli Try version v0.11.0, but since I currently don't have access to a Windows system, I'm unable to test your specific scenario. I can only make some attempts based on what's possible.