6 ms·
--libcurl
- ukuina 3y agoWait, this option would give you a compilable C program that would replace the need for scripting around the original curl call!?
- LoganDark 3y agoThe idea is that you can copy-paste the C code into an existing program or at least use it as a reference to know exactly which libcurl API calls are needed to replicate the curl call.
- notRobot 3y agoYes, it has always been possible with libcurl but you had to write the boilerplate code yourself.
- EasyMark 3y agoyou'd probably have to modify it with a few parameters to make it useful for generic web pages and such, I would think of it as more of a base to build on so you don't have to dig through documents for hours
- oleg_antonyan 3y agoI wish something like this was possible with ffmpeg
- bufo 3y agoSeriously!!
- d3m0t3p 3y agoThat would be awesome
- r0ckarong 3y agoThe compiler has been thinking about the answer for a few decades ...
- donatj 3y agoBefore I found out that statically compiled ffmpeg was a thing, I was trying to compile ffmpeg on a 2010 Mac. It was a multi-day process and every time like two days in I'd hit some snag.
- a3w 3y agoNot our problem, we just need to write the feature request ;) But yes, perhaps as a follow-up, we would need to ask for 1. a speed-up of the process or 2. find a way to look up and redistribute existing conversion flows
- deleted 3y ago[deleted]
- ape4 3y agoUseful idea
- Waterluvian 3y agoI use the browser equivalent of this all the time to generate javascript code for requests. It’s very cool to see this for C and hopefully other languages, too.
- zokier 3y agoOne convenient thing in browser web developer tools is the ability to copy requests from network tab as either curl commands or even as javascript code. I love to see more this sort of things!
- dewey 3y agoAnd was curl is such a "standard" to represent a request there's also many tools converting that curl output into native code (Like Go) already, which makes it very fast to reproduce something without manually having to set all the flags. I'm always happy this feature exists without even needing third party extensions in the browser.
- Joker_vD 3y agoIn an enthusiastic tone of an AI enthusiast: Thankfully, now that we have ChatGPT, this feature is obsolete and the curl executable doesn't have to contain half-baked quines in it anymore!
- ijustlovemath 3y agoIt's not a quine though, as it's not producing curl itself
- tomtomtom777 3y agoOne could argue it's a half-baked quine.
- kevindamm 3y agomm parbaked quine, just pop it in the compiler add a main driver and serve with some gengetopt for a delicious webcrawler!
- throwaway_08932 3y agoIn Italian, it's common to append 'ino' or 'ina' to something when you want to imply it's a smaller or cuter version of itself. So 'quinino' might work here.
- bayindirh 3y agoIf you want something with more rhyme, poco-quine can also work, I guess, pq for short.
- neuromanser 3y agolibpq is taken by PostgreSQL though ;)
- Biganon 3y agoReading this comment gave me a fever... I wish a plant could help me get better...
- smy1es 3y agoThis kind of thing was one of the reasons Visual Basic macros for Microsoft Office was so successful. You can perform actions in Word, Excel, watch the macros they produce then customise themselves to your needs afterwards in code. It is a simple and powerful concept, so good to see it in curl.
- actionfromafar 3y agoI was going to say, there has to be a generic pattern for things like this. Also made me think of AREXX on the Amiga.
- sph 3y agoThere is, but we need to throw away our outdated current programming model. Think Lisp or Smalltalk. There should not be a separation between program written in some language, operating system and shell [1]. You'd simply run: CURL url: "https://example.com" method: 'post in an interactive system, that can either represent your shell, or your application code. We need --libcurl because UNIX is not an interactive environment, so there is an enormous abyss between runtime and compile time. (Syntax in this example from a Smalltalk-like environment I have been designing, should be understandable enough) --- 1: "An operating system is a collection of things that don't fit in a language. There shouldn't be one." — Dan Ingalls, 1981
- supriyo-biswas 3y agoGiven that we already have the concepts of exported entry points and extern in C, this should already be possible to a certain extent. The only other thing which needs to happen is that ELFs should have the concept of exported data structures, so while "URL" might not be a defined structure in the OS, something like curl can provide it. Too bad we're stuck with UNIX/POSIX model - you could even take this idea of exported data structures and have the terminal represent data in the preferred users format instead of having tools like jq.
- sph 3y ago
- jari_mustonen 3y agoPlease also add support for different so we can write —-libcurl example.py
- boffinAudio 3y agoIts quite effective to use ChatGPT to convert C code to Python ..
- a3w 3y ago... or "curl calls to python webscraping". Although having to look for the right version of libraries with different number names and therefore different feature sets was tedious to do manually, AI might just guess fast and sometimes even right as to which import to use.
- justinclift 3y agoYou can probably get pretty far with the generated C code, then look up the same curl options in the Python bindings: https://github.com/pycurl/pycurl https://github.com/pycurl/pycurl
- 0l 3y agoLibcurl is a c/c++ library... Just use Requests
- ok123456 3y agoTools already convert a curl command line to a Python requests script. [1] https://github.com/spulec/uncurl https://github.com/spulec/uncurl
- npteljes 3y agoTry https://curlconverter.com/ https://curlconverter.com/ - "Convert curl commands to Python, JavaScript and more"
- hhthrowaway1230 3y agoI love this! Very nice transition for people to move from commandline to the library when they need to!
- xwowsersx 3y agoHaving a flag in the command line interface that spits out the source code of the program doing the same stuff as your command is pretty cool. It's like lifting the hood and showing you what's going on. This not only helps you get a better grip on how things work but also lets you make changes to fit your needs. You can tweak or add stuff based on what you want, making the whole experience user-friendly. It's all about giving users the power to customize things their way.
- xuhu 3y agoI wish this also worked for Gnome settings, network settings, firewall config GUIs, and anything that can do things using CLI commands.
- INTPenis 3y agoWith dbus we're moving in that direction.
- OskarS 3y agoIt's also just great documentation for a programming library. Like, if you're using libcurl and realize you need to do a range request (or whatever), or "copy as curl" from browser network tab, you can just do it on the command line and add `--libcurl` and find out exactly how to do that with the C library. It's the bee's knees.
- xwowsersx 3y ago100%
- jraph 3y agoNice. Daniel Stenberg is really careful to details and dev / user experience. This level of polishing is astonishing.
- pbaam 3y agoI remember this option was mentioned in a 3 hour video[1] where Daniel Stenberg himself went through most of the curl command line options. [1] https://www.youtube.com/watch?v=V5vZWHP-RqU https://www.youtube.com/watch?v=V5vZWHP-RqU
- deleted 3y ago[deleted]
- ahmedfromtunis 3y agoCan someone give an example use case for this utility? I'm really curious to learn how would you use this?
- Daviey 3y agoThis is really nice, but a feature that some applications implement that I wish was available in the library is some way of outputting curl command line reference which is equivalent of the requests being made. In-fact, I often find myself, MITM'ing myself using burp-suite and "copy as cURL command" feature for exactly this.
- p4bl0 3y agoWhat an awesome idea! That's kind of like a library documentation but alive. Very cool.
- nindalf 3y agoOne pattern I really like is opening the networks tab of the browser, finding the request I'm interested in and "copying as curl" - the browser generates the equivalent command in curl. Then I'd use something like https://curlconverter.com/ https://curlconverter.com/ to convert it into request code of the language I'm using. In a way curl is like the "intermediate representation" that we can use to translate into anything.
- Mavvie 3y agoThis is pretty interesting. It's not like HTTP needs an intermediate representation, but since cURL is so ubiquitous, it ends up functioning as one. cURL is popular so people write tools that can export requests as cURL, and it's popular so people write tools that can import it.
- tracker1 3y agoI've used a similar tool as part of API logging, filtering out the signature on the bearer token... It's useful with request id for dealing with error reporting.
- everforward 3y agoThe benefit of curl over raw HTTP is the ability to strip away things that dont matter. Eg an HTTP request should have a client header, but they're typically not relevant to what you're trying to do. curl is like an HTTP request that specifies only the parts you care about. It's brief, and having access to bash makes it easy to express something like "set this field to a timestamp".
- incorrecthorse 3y agoHTTP requests don't need to have any specific headers, and, if anything, curl will only add ones for you.
- ricardo81 3y agoBut specific HTTP requests might. Like cookies, an accept header, or anything.
- oaiey 3y agoNot sure if I like patching more and more parameters into the executable for gimmicks like this. Would be also work when you exchange the executable name instead of addding a parameter. Like ... curl-as-librucl https://www.example.com
- eichin 3y ago> Added in 7.16.1. > Jan 29 2007 so this isn't a new trend...
- rafaelmn 3y agocode generator that isn't LLM based - how quaint :)
- fullspectrumdev 3y agoTried this out, it doesn’t seem to work at all with a good few flags - notably —upload-file
- Too 3y agoAs if the world needed more unsafe C code connected to the internet. Rust-evangelism aside, I guess one can run the program under ltrace to achieve almost the same result.
- ricardo81 3y agolibcurl is used in billions of situations. Fair point about memory allocations in C, but often alt languages rely on other people's code which you'd implicitly trust to do the same thing. So then it becomes an argument of testing and trust. All the same, you trust strangers code or you write your own.
- ranger_danger 3y agoand often "your own" turns out much buggier.
- ricardo81 3y agoturtles all the way down, just pick your first turtle.
- EasyMark 3y agoI suspect OP has already made up their mind on using C at all :)
- ricardo81 3y ago:) Stabilisers for some, but definitely not others.
- avgcorrection 3y ago> As if the world needed more unsafe C code connected to the internet. Assuming (as usual) that the code generation is solid because of curl’s reputation: why not trust it? It would be pretty bad if the generator could emit memory-unsafe code. (I don’t know.)
- pimlottc 3y agoThe submission title should be two hyphens (--), not an em-dash and a hyphen (—-)
- altairprime 3y agoEmailing the mods about this would enable them to see your comment and fix it; use the Contact link in the footer.
- pimlottc 3y agoReported, thanks!
- chfritz 3y agoIt says everything about C when you need a code generator for something like this. This is why development in python or node.js is so much faster.
- pimlottc 3y agoSomeone should buy libcurl.com and make it return the source code to generate a request to itself. Bonus points for setting the same headers and options as the triggering request.
- LatticeAnimal 3y agoSadly, it looks like godaddy is charging $5000 for the domain. Otherwise that would be a fun project.
- nicoster 3y agothis may not be as useful as it appears since different requests are for different different URLs, unless you redirect a request to libcurl.com
- jicea 3y agoShameless promotion: Hurl [1] is an Open Source cli using libcurl to run to test HTTP requests with plain text! We use libcurl for the super reliability and top features (HTTP/3 for instance) and we've added little features like: - requests chaining, - capturing and passing data from a response to another request, - response tests (JSONPath, XPath, etc...) There is nice syntax sugar for requesting REST/SOAP/GraphQL APIs but, at the core, it's just libcurl! Using verbose option, you can grep the curl commands for instance. (I'm one of the maintainers) [1]: https://hurl.dev https://hurl.dev
- cassepipe 3y agoUsed it and really liked it Thanks for your work
- fweimer 3y agoI think I saw this first with the ASM bytecode toolkit: https://asm.ow2.io/javadoc/org/objectweb/asm/util/ASMifier.html https://asm.ow2.io/javadoc/org/objectweb/asm/util/ASMifier.h... Possibly via the Eclipse extension: https://marketplace.eclipse.org/content/bytecode-outline https://marketplace.eclipse.org/content/bytecode-outline
- undecisive 3y agoTo compile it you'll need to tell it to link to libcurl, e.g. with -lcurl on gcc: curl https://ifconfig.me --libcurl ip_fetcher.c # Output: your ip address, and a file ip_fetcher.c gcc -o ip_fetcher ip_fetcher.c -lcurl # Output: no errors, just a file ip_fetcher ./ip_fetcher # Output: your ip address (I'm sure most people are saying "no duh" right now, but I'm probably not the only one on here who doesn't write C code every day!)
- chungy 3y agoIt might be even easier this way: $ curl https://ifconfig.me --libcurl ip_fetcher.c $ make LDFLAGS=-lcurl ip_fetcher $ ./ip_fetcher (I just find make a heck of a lot easier than running direct cc commands)
- undecisive 3y agoTIL - I have never used make without a Makefile! Thank you!
- theanonymousone 3y agoIs there any libcurl wrapping for Java?
- junon 3y agoOf course there is.
- deleted 3y ago[deleted]
- EasyMark 3y agodang.... i wish I knew that when I was working on my own little hacker news filter program just to practice some old school c >:(
- deleted 3y ago[deleted]