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

Progress callbacks in HTTPLite #114

Open
Splendide-Imaginarius opened this issue Oct 31, 2023 · 10 comments
Open

Progress callbacks in HTTPLite #114

Splendide-Imaginarius opened this issue Oct 31, 2023 · 10 comments

Comments

@Splendide-Imaginarius
Copy link

Splendide-Imaginarius commented Oct 31, 2023

@enumag requested progress callbacks in HTTPLite. Looks like this should be easy since cpp-httplib already supports this on the C++ side.

@enumag
Copy link

enumag commented Oct 31, 2023

An easy way to do this would be to copy the HTTPLite.download method from JoiPlay which would also make cross-compatibility easier.

HTTPLite.download method downloads a file to a given path. Usage: HTTP.download(url, filepath, progresscallbackmethodname, headers) Callback method must accept two fixnums (progress, total).

https://github.com/joiplay/mkxp/blob/master/src/http.h#L15
https://github.com/joiplay/mkxp/blob/master/src/http.cpp#L63
https://github.com/joiplay/mkxp/blob/master/binding-mri/http-binding.cpp#L49

I'll see if my team actually needs it and try to contribute it if we do.

@enumag
Copy link

enumag commented Nov 2, 2023

We'd really like to have this available. However the related code seems to be very different between JoiPlay and mkxp-z so it's not possible to just copy it as I first thought. mkxp-z doesn't even have a http.h and http.cpp files. I have no experience with C++ so it seems I won't be able to contribute this unfortunately. Still I'd really appreciate if it was available. It's hopefully not too difficult for an experienced C++ programmer?

It doesn't really matter if the API is the same as in JoiPlay or not, I can easily add a condition in the script. I just need it to be able to write the response body into a file (HTTPLite.get seems to put the entire response body into a variable which isn't ideal) and be able report progress using a callback or something.

@Splendide-Imaginarius
Copy link
Author

I'm happy to give it a look, but it may take me some time due to other priorities. If anyone else wants to give this a try before I get to it, I would really like the API to match JoiPlay unless there's some reason not to do so.

@Splendide-Imaginarius
Copy link
Author

It's hopefully not too difficult for an experienced C++ programmer?

In this case, my C++ experience isn't an issue, but my experience with Ruby definitely is (since this involves interaction between C++ and Ruby code, and I've only been using Ruby for just over a year). I'm pretty good at learning fast, so I don't anticipate being unable to implement this, but I will definitely have to learn some stuff to do it.

@enumag
Copy link

enumag commented Nov 2, 2023

With the findings from #118 I should be able to use net/http instead so this is probably unnecessary.

@Splendide-Imaginarius
Copy link
Author

Noted, and thanks for finding an alternative solution! I'd still happily accept a PR for adding this if the API matches JoiPlay, but good to know I can lower the priority on this for now.

@enumag
Copy link

enumag commented Nov 2, 2023

Note that it's not yet confirmed that net/http will work, it's just a hypothesis for now. I didn't try it yet. :) I'll let you know how it goes ofc.

@enumag
Copy link

enumag commented Nov 2, 2023

Alright so... net/http does work as long as I avoid https. With https it fails like this:

Exception `LoadError' at C:/Projects/Reborn/Rejuvenation/stdlib/net/http.rb:1627 - cannot load such file -- openssl

So what's the issue with openssl? In mkxp-z's code there are plenty ifs and code regarding openssl, for instance this:

mkxp-z/src/meson.build

Lines 41 to 53 in 52c932b

# If OpenSSL is present, you get HTTPS support
if get_option('enable-https') == true
openssl = dependency('openssl', required: false, static: build_static)
if openssl.found() == true
global_dependencies += openssl
global_args += '-DMKXPZ_SSL'
if host_system == 'windows'
global_link_args += '-lcrypt32'
endif
else
warning('Could not locate OpenSSL. HTTPS will be disabled.')
endif
endif

Which seems to indicate that it should be possible to get openssl working. What's required to actually enable it?

@enumag
Copy link

enumag commented Nov 18, 2023

We managed to sort out https issues as well in #118 so I think this can be closed now.

@Splendide-Imaginarius
Copy link
Author

I'm a little ambivalent on whether to close this since maybe someone wants this for HTTPLite specifically rather than via the Ruby standard library. Anyone have opinions on whether doing this with HTTPLite is a legit use case given that the Ruby stdlib seems to be an alternative?

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

2 participants