-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
feat: add HTTPClient implementation using curl as a module #50964
Conversation
Wasn't this implemented by #49026?
I would only enable HTTP support (both HTTP/1.x and HTTP/2). FTP support is rarely used nowadays.
We can add something to CI that runs a Godot project configured to make HTTP requests against a resource known for its high uptime, such as https://httpbin.org. If any of the requests fail, exit the project with a non-zero exit code ( |
Few things also mentioned in the chat:
When you want to handle the request in a thread.
If we don't use our NetSocket implementation, just have them do nothing/return null and spit an error. Like JavaScript does: godot/platform/javascript/http_client_javascript.cpp Lines 74 to 76 in 0caaaf4
Well, be happy, you won't have to write any new doc, given you are creating a new implementation of an exposed class, not a new exposed class (so HTTPClient is already fully documented).
Yeah, this is going to be quite annoying, on Linux I only got it to work with system-wide mbedtls (not with built-in) and using @fire |
I had testing for HTTPClient on a separate repository like the one you are proposing (those are not unit tests): We can use those to verify the correct behaviour, the main problem was that websites would, from time to time slightly change their layout, so of course tests would unexpectedly break. |
Size comparison ( |
Yes, the engine supports it. This code, however does not. I am also unsure whether it's possible to do in an async manner. It's also worth mentioning that the current HTTPClient implementation does not seem to do multi address resolution, so Im gonna leave it to be outside the scope of this PR for now. |
Okay I've trimmed down the TODO list a bit.
Fixed this. Also, @Faless I've updated the code to use the async resolver polling. It's basically the same code as the existing HTTPClientTCP you referenced, so nothing too crazy there. Still can't get IPv6 to work and still not quite groking the blocking mode stuff. I've left a couple messages in the dev chat. |
This is ready for review. I've tested this on Windows using the attached project, however it should probably be tested on linux, osx, android, and ios as well for posterity. |
Would be great to squash, leaving 2 commits, one adding the third-party library the other adding the module itself. |
@jonbonazza Will work on rebasing into two prs and resolving the reviews. |
d028cdd
to
8546adb
Compare
Historical note: The module name |
In file included from thirdparty/curl/lib/vtls/mbedtls.c:59:
thirdparty/curl/lib/sendf.h:37:2: error: "missing VARIADIC macro define, fix and rebuild!"
#error "missing VARIADIC macro define, fix and rebuild!"
^
Compiling ==> thirdparty/curl/lib/bufref.c
1 error generated.
scons: *** [thirdparty/curl/lib/vtls/mbedtls.windows.opt.tools.64.o] Error 1
In file included from thirdparty/curl/lib/altsvc.c:35:
thirdparty/curl/lib/sendf.h:37:2: error: "missing VARIADIC macro define, fix and rebuild!"
#error "missing VARIADIC macro define, fix and rebuild!"
^
1 error generated.
scons: *** [thirdparty/curl/lib/altsvc.windows.opt.tools.64.o] Error 1
In file included from thirdparty/curl/lib/asyn-thread.c:67:
thirdparty/curl/lib/sendf.h:37:2: error: "missing VARIADIC macro define, fix and rebuild!"
#error "missing VARIADIC macro define, fix and rebuild!"
^
1 error generated.
scons: *** [thirdparty/curl/lib/asyn-thread.windows.opt.tools.64.o] Error 1
In file included from thirdparty/curl/lib/vtls/vtls.c:55:
thirdparty/curl/lib/sendf.h:37:2: error: "missing VARIADIC macro define, fix and rebuild!"
#error "missing VARIADIC macro define, fix and rebuild!"
^
1 error generated.
scons: *** [thirdparty/curl/lib/vtls/vtls.windows.opt.tools.64.o] Error 1 Using mingw llvm. /bin/bash -c "PATH=/opt/llvm-mingw/bin:$PATH scons werror=no platform=windows target=release_debug -j`nproc` use_lto=no deprecated=no use_mingw=yes use_llvm=yes use_lld=yes use_thinlto=yes LINKFLAGS=-Wl,-pdb= CCFLAGS='-g -gcodeview' debug_symbols=no custom_modules=../godot_custom_modules" |
@fire I've reduced the commits down to 2. |
9ae14fa
to
c918d7e
Compare
It doesn't so handle HEAD requests correctly:
Please refer to https://github.com/Faless/gd-tests/ (quite outdated) for some test URL. Please test at least:
Would be better to also test:
|
e0567f3
to
5f019e6
Compare
@Faless okay, I've tested every HTTP method I could think of and both chunked and not chunked for the ones that made sense. I also went through all the tests in your test project and made sure my responses matched what the tests expected. I also added all of the default headers that the old http client was adding. One thing is I did screw up the git history so I ended up just squashing everything down. |
FWIW, a suuuper handy tool for doing these tests was https://httpbin.org |
I just want to chime in and say that its awesome how consistently you've been working away on this. Thanks for the efforts! |
More bugs were founds. Squashing. 🐞 |
Co-authored-by: Jon Bonazza <jonbonazza@gmail.com> Co-authored-by: Fabio Alessandrelli <fabio.alessandrelli@gmail.com>
Ooookay. Squashed all the bugs I found. @fire the issue you found should also be resolved. |
I can still see a bug. Having trouble reducing a test case. |
This feature looks great (as at the moment I'm having to use a GDNative extension), will it be merged anytime soon? |
Looks like it has merge conflicts at the moment. |
This feature is abandoned. |
Closing after discussion at the Valencia sprint - besides this being obviously abandoned now, this was more difficult than anticipated, the upsides were smaller than hoped, and all in all the networking team now feels this is firmly in GDExtension territory for now. Huge thanks to jonbonazza for exploring this and spending so much time on the implementation. (And of course to everyone reviewing :)) |
This PR uses libcurl in multi mode (curl_multi) to implement the HTTPClient interface. It cleans up the implementations significantly and should reduce maintenance burden while giving us easier access to more features in the end.
fixes godotengine/godot-proposals#2903
Scope
The goal of this PR is only to create a curl-based implementation of
HTTPClient
that conforms to the existing interface and nothing more.The net team has discussed several improvements to the
HTTPClient
interface in general that may be implemented in future PRs, but they remain outside the scope of this one.Remaining Work
The current state of the PR is DRAFT. It still needs more testing and there are still a few remaining pieces left.
set_connection
andget_connection
. The way libcurl works doesn't lend itself well to theStreamPeer
interface, so without some changes to that API, there's not a good way to do t his. If we do decide to useNetSocket
as the socket implementation (see above item) then we get this for free, so that's one pro to that approach. That said, I don't see these functions used anywhere in the Godot codebase, so I'd question whether they are even needed to begin with.If I've missed anything in either the implementation itself, or the TODO list above, please don't hesitate to bring it up so we can discuss and potentially address it.
Regarding Unit Tests
While we should certainly strive for as much unit tests coverage as possible, I didn't see any existing tests for the http client, so I've decided to leave that for an exercise for another day (and potentially another person).
I want to stress that my decision not to include unit tests is not to the discredit of the idea of unit tests in general; quite the contrary, in fact. I would like to see a day where Godot's unit test coverage nears 100% just as much as anyone. However the best way to test http code is by running it against a real HTTP server, and to my knowledge, Godot doesn't currently have the facilities to do that and I'm not comfortable convoluting this particular PR by adding those facilities.
A Note About The Commits
There's quite a lot of commits in this one and none of them are particularly clean. I'm a bit embarrassed about that, but it's mostly due to the fact I was learning so many new technologies along the way and ended up doing a lot of things wrong in a lot of different places in odd orders.
I suggest when merging this PR to squash all of the commits in order to keep things as clean as possible in master.