🐱‍👤 Drop-in HTTP replacement module for Garry's Mod

Overview

🐱‍👤 gmsv_reqwest

This module is a drop-in replacement for Garry's Mod's HTTP function, inspired by gmsv_chttp created by timschumi.

The module uses the reqwest crate for dispatching HTTP requests, tokio crate for async/thread scheduling runtime and the rustls crate for SSL/TLS.

This module was written in Rust and serves as a decent example on how to write a Garry's Mod binary module in Rust. (Thank you Willox for the base!)

Installation

Download the relevant module for your server's operating system and platform/Gmod branch from the releases section.

Drop the module into garrysmod/lua/bin/ in your server's files. If the bin folder doesn't exist, create it.

If you're not sure on what operating system/platform your server is running, run this in your server's console:

lua_run print((system.IsWindows()and"Windows"or system.IsLinux()and"Linux"or"Unsupported").." "..(jit.arch=="x64"and"x86-64"or"x86"))

Usage

To use reqwest in your addons, you can put this snippet at the top of your code, which will fallback to Gmod's default HTTP function if reqwest is not installed on the server.

if pcall(require, "reqwest") and reqwest ~= nil then
    my_http = reqwest
else
    my_http = HTTP
end
Comments
  • Conflict: Srlion's Hook Library

    Conflict: Srlion's Hook Library

    Architecture: Linux 32 bit

    https://steamcommunity.com/sharedfiles/filedetails/?id=1907060869

    If gmsv_reqwest is installed alongside Srlion's Hook library (on Linux 32 - no other tests have been carried out as of yet) the console gets consumed with the error `[Srlion's Hook Library] attempt to index a string value

    1. func - [C]:-1
    2. unknown - lua/includes/modules/hook.lua:241`
    opened by FelixKLG 20
  • Game crash on require(

    Game crash on require("reqwest")

    My game crashes instantly whenever i do require("reqwest") on serverside, tried in p2p and singleplayer, no crash logs are generated. Any idea what could cause this?

    opened by wrefgtzweve 10
  • TraceLine error when onfailed function is passed and request is success

    TraceLine error when onfailed function is passed and request is success

    Details

    Protocol version 24 Exe version 2021.06.09 (garrysmod) Exe build: 14:40:17 Jul 12 2021 (8283) (4000) GMod version 2021.07.12, branch: unknown, multicore: 0 Windows 32bit

    Step to reproduce

    Sandbox gamemode No addons enabled No other modules included main branch (tested with 1.1.1, 1.1.0, 1.0.0 module versions)

    if not reqwest then
    	require"reqwest"
    end
    
    local function onfailed(r)
    	print("Failed:", r)
    end
    
    local function onsuccess(code, body, headers)
    	print("Success:", code, headers)
    end
    
    reqwest({
    	failed = onfailed,
    	success = onsuccess,
    	method = "GET",
    	url = "https://github.com/WilliamVenner/gmsv_reqwest"
    })
    

    Result:

    Success:	200	table: 0x466aac48
    
    [ERROR] attempt to index a function value
      1. TraceLine - [C]:-1
       2. UpdateHovered - lua/includes/modules/widget.lua:46
        3. PlayerTick - lua/includes/modules/widget.lua:89
         4. v - lua/includes/modules/widget.lua:149
          5. unknown - lua/includes/modules/hook.lua:84
    

    No error when failed func not passed

    if not reqwest then
    	require"reqwest"
    end
    
    local function onsuccess(code, body, headers)
    	print("Success:", code, headers)
    end
    
    reqwest({
    	success = onsuccess,
    	method = "GET",
    	url = "https://github.com/WilliamVenner/gmsv_reqwest"
    })
    

    Result:

    Success:	200	table: 0x177709d8
    

    Also no error when request is failed

    if not reqwest then
    	require"reqwest"
    end
    
    local function onfailed(r)
    	print("Failed:", r)
    end
    
    local function onsuccess(code, body, headers)
    	print("Success:", code, headers)
    end
    
    reqwest({
    	failed = onfailed,
    	success = onsuccess,
    	method = "GET",
    	url = "https://this_willbe_failed/"
    })
    

    Result:

    Failed:	unsuccessful
    
    opened by klen-list 1
  • Linux x32 build won't require due to missing GLIBC version

    Linux x32 build won't require due to missing GLIBC version

    I'm using Ubuntu 16.04, this issue seems to be when it's compiled with a version of GLIBC that is too high for people running certain Ubuntu versions.

    [ERROR] error loading module 'reqwest' from file 'gmsv_reqwest_linux.dll':
            /lib/i386-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by /home/container/garrysmod/lua/bin/gmsv_reqwest_linux.dll)
      1. error - [C]:-1
       2. searcher - lua/test.lua:65
        3. require - lua/test.lua:148
         4. unknown - lua_run:1
    

    Similar issue: https://github.com/FredyH/GWSockets/issues/10

    opened by Jabbers99 1
  • feat: add loading of custom root certificates.

    feat: add loading of custom root certificates.

    This pull request allows for the addition of custom root certificates, by adding them into the: garrysmod/tls_certificates directory. As per the readme:

    To add custom root certificates, place them in the "garrysmod/tls_certificates" directory. The certificates must be X509 and encoded in either pem or der. They must also end in the .pem or .der file extensions respective to their econding. If there is a problem loading the certificate, it'll be skipped over and a message will be displayed in the console.

    opened by NoSharp 0
Releases(v3.0.2)
Owner
William
aka Billy
William
An HTTP library for Rust

hyper A fast and correct HTTP implementation for Rust. HTTP/1 and HTTP/2 Asynchronous design Leading in performance Tested and correct Extensive produ

null 11k Jan 8, 2023
An easy and powerful Rust HTTP Client

reqwest An ergonomic, batteries-included HTTP Client for Rust. Plain bodies, JSON, urlencoded, multipart Customizable redirect policy HTTP Proxies HTT

Sean McArthur 6.8k Dec 31, 2022
FeignHttp is a declarative HTTP client. Based on rust macros.

FeignHttp is a declarative HTTP client. Based on rust macros. Features Easy to use Asynchronous request Configurable timeout settings Suppor

null 46 Nov 30, 2022
Pretend is a macros-based declarative Rust HTTP client

pretend is a modular, Feign-inspired HTTP, client based on macros. It's goal is to decouple the definition of a REST API from it's implementation.

null 24 Aug 3, 2022
Multi-stream HTTP downloader using range requests

chooch - An Amazing Project Downloads files faster than wget/curl (in theory) using multiple connections. Chooch recycles the slowest connection and r

null 13 Sep 14, 2022
Pyre - A fast python HTTP server inspired by japronto written in rust.

Pyre - A fast python HTTP server inspired by japronto written in rust.

null 135 Nov 26, 2022
Minimal Rust HTTP client for both native and WASM

ehttp: a minimal Rust HTTP client for both native and WASM If you want to do HTTP requests and are targetting both native and web (WASM), then this is

Emil Ernerfeldt 105 Dec 25, 2022
Fast and friendly HTTP server framework for async Rust

Tide Serve the web API Docs | Contributing | Chat Tide is a minimal and pragmatic Rust web application framework built for rapid development. It comes

http-rs 4.1k Jan 2, 2023
HTTPie: human-friendly CLI HTTP client for the API era

HTTPie: human-friendly CLI HTTP client for the API era HTTPie (pronounced aitch-tee-tee-pie) is a command-line HTTP client. Its goal is to make CLI in

null 25.4k Dec 30, 2022
xh is a friendly and fast tool for sending HTTP requests. It reimplements as much as possible of HTTPie's excellent design, with a focus on improved performance.

xh is a friendly and fast tool for sending HTTP requests. It reimplements as much as possible of HTTPie's excellent design, with a focus on improved performance

Mohamed Daahir 3.4k Jan 6, 2023
ratpack: a simpleton's HTTP framework (for rust-lang)

ratpack: a simpleton's HTTP framework (for rust-lang) ratpack is idealized in the simplicity of the sinatra (ruby) framework in its goal, and attempts

ZeroTier, Inc. 5 Jun 29, 2022
A backend providing a HTTP REST like interface for uploading files written in rust.

UploadServer A backend providing a HTTP REST like interface for uploading files written in rust. API Documentation License This project is licensed un

null 4 Nov 20, 2022
rh: user-friendly command-line HTTP client

Rust HTTP Cli The command name in your terminal is rh. rh: user-friendly command-line HTTP client rh is a user-friendly, lightweight and performant co

null 8 Nov 30, 2022
Drop-in replacement for the Actix Web HTTP Logger middleware

actix-contrib-logger Logger middleware for the Actix Web framework. Actually it's a copy & paste from the official Logger middleware (original source

Mariano Ruiz 5 Aug 28, 2023
Easy c̵̰͠r̵̛̠ö̴̪s̶̩̒s̵̭̀-t̶̲͝h̶̯̚r̵̺͐e̷̖̽ḁ̴̍d̶̖̔ ȓ̵͙ė̶͎ḟ̴͙e̸̖͛r̶̖͗ë̶̱́ṉ̵̒ĉ̷̥e̷͚̍ s̷̹͌h̷̲̉a̵̭͋r̷̫̊ḭ̵̊n̷̬͂g̵̦̃ f̶̻̊ơ̵̜ṟ̸̈́ R̵̞̋ù̵̺s̷̖̅ţ̸͗!̸̼͋

Rust S̵̓i̸̓n̵̉ I̴n̴f̶e̸r̵n̷a̴l mutability! Howdy, friendly Rust developer! Ever had a value get m̵̯̅ð̶͊v̴̮̾ê̴̼͘d away right under your nose just when

null 294 Dec 23, 2022
An experimental HTTP server in Rust that supports HTTP/1.1, HTTP/2, and HTTP/3 over QUIC.

?? H123 An experimental HTTP server in Rust that supports HTTP/1.1, HTTP/2, and HTTP/3 over QUIC. Warning This is an experimental project and not inte

Naoki Ikeguchi 7 Dec 15, 2022
Rustyread is a drop in replacement of badread simulate.

Rustyread is a drop in replacement of badread simulate. Rustyread is very heavily inspired by badread, it reuses the same error and quality model file. But Rustyreads is multi-threaded and benefits from other optimizations.

Pierre Marijon 20 Oct 1, 2022
age-encrypted secrets for NixOS; drop-in replacement for agenix

ragenix ragenix provides age-encrypted secrets for NixOS systems which live in the Nix store and are decrypted on system activation. Using ragenix to

YAXI 91 Jan 8, 2023
A drop-in replacement for `dapp` and `seth` in Rust

dapptools.rs Rust port of DappTools dapp example Usage Run Solidity tests Any contract that contains a function starting with test is being tested. Th

Georgios Konstantopoulos 5k Jan 1, 2023
A (mostly) drop-in replacement for Rust's Result that provides backtrace support

Errant A (mostly) drop-in replacement for Rust's Result that provides backtrace support. Please note that Errant is still very early in development an

Joshua Barretto 17 Dec 26, 2022