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

Introduce HTTP API for plugins #5383

Merged
merged 46 commits into from
Jun 22, 2024
Merged

Conversation

Mm2PL
Copy link
Collaborator

@Mm2PL Mm2PL commented May 6, 2024

This adds a new API: c2.HTTPRequest that requires a new permission: Network.

@Mm2PL Mm2PL changed the title Add Lua HTTP API Introduce HTTP API for plugins May 6, 2024
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

src/controllers/plugins/Plugin.cpp Show resolved Hide resolved
@Mm2PL Mm2PL force-pushed the feature/chatterino-lua-http-api branch 2 times, most recently from 5a2a45a to a32fcb8 Compare May 6, 2024 21:52
@Mm2PL Mm2PL force-pushed the feature/chatterino-lua-http-api branch from a32fcb8 to 1d850d1 Compare May 6, 2024 21:54
@Mm2PL Mm2PL requested a review from pajlada May 7, 2024 13:01
Copy link
Member

@pajlada pajlada left a comment

Choose a reason for hiding this comment

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

Design question:
Maybe rename the permission from HTTP to Network? I think this more accurately describes what the plugin will actually be allowed to do, with less of a technical description.
"Allows the plugin to make network requests over your network/over the internet/to third party websites".

Bit of an early review, haven't looked into the implementation of anything

docs/plugin-meta.lua Show resolved Hide resolved
src/controllers/plugins/Plugin.cpp Outdated Show resolved Hide resolved
src/controllers/plugins/Plugin.cpp Show resolved Hide resolved
Copy link
Contributor

@Nerixyz Nerixyz left a comment

Choose a reason for hiding this comment

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

The following code segfaults after a short while:

local function send_req()
    local req = c2.HTTPRequest.create(c2.HTTPMethod.Get, "https://postman-echo.com/get")
    req:on_success(function(res)
    end)
    req:on_error(function(result)
    end)
    req:execute()
    c2.later(send_req, 100)
end

send_req()

The crash happens in the handlers of the request. Looking at the captured L, it's probably the thread from c2.later getting deleted while the callbacks hold on to it through lua_State.

src/controllers/plugins/api/HTTP.cpp Outdated Show resolved Hide resolved
src/controllers/plugins/api/HTTP.cpp Outdated Show resolved Hide resolved
@Mm2PL
Copy link
Collaborator Author

Mm2PL commented May 7, 2024

The crash happens in the handlers of the request. Looking at the captured L, it's probably the thread from c2.later getting deleted while the callbacks hold on to it through lua_State.

I'll have to store an ID of the plugin or something and get the state back then.

iProdigy

This comment was marked as resolved.

@Mm2PL Mm2PL force-pushed the feature/chatterino-lua-http-api branch from 5b9f905 to 5a4e64c Compare June 17, 2024 13:11
@Mm2PL Mm2PL marked this pull request as ready for review June 18, 2024 20:56
@Mm2PL Mm2PL requested a review from pajlada June 19, 2024 11:36
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

src/controllers/plugins/LuaAPI.hpp Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

src/controllers/plugins/LuaAPI.hpp Show resolved Hide resolved
@pajlada pajlada enabled auto-merge (squash) June 22, 2024 09:37
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

src/controllers/plugins/LuaAPI.hpp Show resolved Hide resolved
@pajlada pajlada merged commit c980162 into master Jun 22, 2024
17 checks passed
@pajlada pajlada deleted the feature/chatterino-lua-http-api branch June 22, 2024 10:04
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

Successfully merging this pull request may close these issues.

4 participants