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

Get progress in callback for HTTP requests #8604

Merged
merged 19 commits into from Mar 13, 2024
Merged

Conversation

Jhonnyg
Copy link
Contributor

@Jhonnyg Jhonnyg commented Feb 28, 2024

Added a new parameter to the option table for the http.request function called 'report_progress'. When report_progress is true, the amount of bytes sent and/or received for a request will be passed into the callback function:

http.request("http://my-address", "GET",
	function(self, id, response)
		if response.bytes_total ~= nil then
			update_my_progress_bar(self, response.bytes_received / response.bytes_total)
		else
			-- handle response like normal
		end
	end,
	nil, nil, { report_progress = true })

Fixes #6486

@@ -855,8 +857,6 @@ if (sock_res != dmSocket::RESULT_OK)\
r = RESULT_OK;
break;
}

++chunk_number;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused

Comment on lines -37 to 40
#define JC_TEST_IMPLEMENTATION
#include <jc_test/jc_test.h>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using the test_gamesys.h in the HTTP gamesys tests

dmGameSystem::FinalizeScriptLibs(scriptlibcontext);
}

int main(int argc, char **argv)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is here for two reasons:

  • I don't want to mess the current HTTP tests up that was moved into gamesys
  • I don't want to put this into the main gamesys test because it relies on a http server running, and the gamesys test is getting a bit out of hand size wise

@@ -0,0 +1,18 @@

def do_GET(req):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to reuse the script test server, so I added a simple plugin mechanism to it

Comment on lines +21 to +22
target = 'test_script',
source = 'test_script.cpp test_script_private.cpp')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reuse this in the gamesys http tests now

@Jhonnyg Jhonnyg requested review from JCash and britzl March 1, 2024 13:13
@Jhonnyg Jhonnyg marked this pull request as ready for review March 1, 2024 14:12
britzl
britzl previously approved these changes Mar 1, 2024
Copy link
Contributor

@britzl britzl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lua API wise it looks good I think. Backwards compatible and easy to use. I'll let @JCash comment on the other code changes.

JCash
JCash previously approved these changes Mar 4, 2024
@Jhonnyg Jhonnyg dismissed stale reviews from JCash and britzl via cabbfe9 March 13, 2024 14:13
@Jhonnyg Jhonnyg merged commit 8d5d85f into dev Mar 13, 2024
9 of 15 checks passed
@Jhonnyg Jhonnyg deleted the http-request-progress-old branch March 14, 2024 15:41
@Jhonnyg Jhonnyg added feature request A suggestion for a new feature engine Issues related to the Defold engine labels Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
engine Issues related to the Defold engine feature request A suggestion for a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Report progress for http.request calls
4 participants