[Release] plutonium-http

Topic created · 4 Posts · 188 Views
  • Visit this project on Github: https://github.com/ryanocf/plutonium-http


    plutonium-http

    Making it possible to do basic http GET, POST, PUT & DELETE requests within ChaiScript.
    This plugin was mainly built for Plutonium MW3.


    Download

    Download the latest release and put the plutonium-http.dll in your servers plugin folder.


    Usage

    ❗ OpenSSL is currently not supported.
    Every function returns the same Vector scheme:

    0: version // String
    1: error // String
    2: status // Int
    3: reason // String
    4: body // String
    5: headers // Map
    
    /*
     * Params
     * url: String
     * route: String
     * headers: Map
     *
     * return: Vector
     */
    http_get("http://example.com", "/route", ["header": "value"]);
    
    /*
     * Params
     * url: String
     * route: String
     * body: String
     * headers: Map
     * content_type: String
     *
     * return: Vector
     */
    http_post("http://example.com", "/route", "body", ["header": "value"], "text/plain");
    http_post("http://example.com", "/route", "param=body&format=string", ["header": "value"], "application/x-www-form-urlencoded");
    
    /*
     * Params
     * url: String
     * route: String
     * body: String
     * headers: Map
     * content_type: String
     *
     * return: Vector
     */
    http_put("http://example.com", "/route", "body", ["header": "value"], "text/plain");
    http_put("http://example.com", "/route", "param=body&format=string", ["header": "value"], "application/x-www-form-urlencoded");
    
    /*
     * Params
     * url: String
     * route: String
     * body: String
     * headers: Map
     * content_type: String
     *
     * return: Vector
     */
    http_delete("http://example.com", "/route", "body", ["header": "value"], "text/plain");
    http_delete("http://example.com", "/route", "param=body&format=string", ["header": "value"], "application/x-www-form-urlencoded");
    

    Errors

    std::array<std::string, 13> error_list = {
        "Success",
        "Unknown",
        "Connection",
        "BindIPAddress",
        "Read",
        "Write",
        "ExceedRedirectCount",
        "Canceled",
        "SSLConnection",
        "SSLLoadingCerts",
        "SSLServerVerification",
        "UnsupportedMultipartBoundaryChars",
        "Compression"
    };
    

    Any questions or problems?
    Feel free to open an issue or visit this project on Plutonium.

    Credits

    https://github.com/yhirose/cpp-httplib
    https://github.com/ChaiScript/ChaiScript
    https://github.com/xensik/plutoscript

  • The idea is cool, but you should make an asynchronous implementation.

    You are blocking the entire game thread with the http calls. this way is not very usable. Its specified in the cpp-httplib README that is a blocking library.

  • @xensik
    Thanks for the feedback.
    Yeah, I knew that tho I wanted to use an easy to port library (c++ -> chai).

    I haven't put that much thoughts into it tbh. but I will look into options on making the functions like tasks/threads.
    I don't have that high hopes bc. plugins are getting loaded/injected into the running server process sooo.. yeah I probably have to switch the library.

    For now, the best use case would be to do requests at the plugin's initialization and don't mess with it too much while players are on the server.

  • @ryano_
    you don't need to switch the library, but need a layer in between.

    you can make something like:

    • create 2 queues (requests and responses) with data and a chai callback

    • create a worker thread that wakes up when requests not empty, process them and store the result in responses queue.

    • create a hook at server frame, if responses not empty, call the chai callback with the response data.

    and the chai functions ('http_get '...) just store the data and callback in requests queue.

Log in to reply