Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http library #334

Open
0dminnimda opened this issue Oct 26, 2024 · 5 comments
Open

http library #334

0dminnimda opened this issue Oct 26, 2024 · 5 comments

Comments

@0dminnimda
Copy link

Is there any http library, like pythons 'requests'?
I know it's an unfinished language, just wondering whether anything like that exists, didn't find mentions of such thing in the source code.

@aardappel
Copy link
Owner

Does not exist yet, sorry.. we've had plans to add one, but likely that should be based on a C++ http library that is small, robust and still featureful, and its hard to find such things. In particular, if you are expecting to support https, there is probably no such thing :)

@shamrin
Copy link
Contributor

shamrin commented Nov 20, 2024

I've briefly looked into what Lobster http client can be based on. Observations:

  • libcurl with a selection of TLS libraries
  • Node.js uses OpenSSL and llhttp with a wrapper.
  • Ladybird browser uses its own LibHTTP library. Looks nice, but probably not fully battle-tested yet and hard to decouple from the rest of Ladybird.
  • It may be a good idea to use non-C++ library, when the language has great C/C++ interop. For example, Zig, that includes HTTP and TLS in the standard library.
  • Python converged on (bring-your-own-IO) h11/h2 + httpcore + httpx. Can't be used in Lobster, but interesting to see what other language communities do.

@aardappel
Copy link
Owner

Stuff like libcurl is positively gigantic. Making Lobster build 10x as long for http(s) support is not really an option.

Zig is neat but wouldn't want to complicate the build system by involving another compiler. It really needs to be standalone C++ that can be added to the build system of the 6 platforms Lobster builds on.

One option for these possibly gigantic features is to build it as a standalone dll/so, that can optionally be loaded into Lobster. So a lib that combines something like libcurl with some Lobster bindings. Or even keep the bindings in Lobster but just use the dll interface. That way users that don't need http(s) don't pay for it.

@0dminnimda
Copy link
Author

I'd say the easiest way would be to precompile a static library and hook it up when building the program. The only requirement is to have ffi in the language.

@shamrin
Copy link
Contributor

shamrin commented Nov 20, 2024

Zig can compile to C file, which can later be built without Zig. The .c artifact is unfortunately big (32 Mb) and obviously not for human consumption. I did a quick experiment with Zig http example on my laptop:

$ time zig build-exe main.zig -ofmt=c -OReleaseSmall
        0.99 real         1.10 user         0.09 sys
$ time clang main.c -w -Os -o main -lpthread
       12.65 real        12.45 user         0.15 sys
$ ls -lh
-rwxr-xr-x  1 user  user   725K … main*
-rw-r--r--  1 user  user    32M … main.c
-rw-r--r--  1 user  user   1.3K … main.zig
-rw-r--r--  1 user  user   150K … zig.h

Direct compile, for comparison:

$ time zig build-exe main.zig -OReleaseSmall
        7.49 real         7.02 user         0.21 sys
$ ls -lh main
-rwxr-xr-x  1 user  user   713K … main*

(Removing optimization flags like -Os drops the time down to 4-5 seconds.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants