Facepunch / garrysmod-requests

Feature requests for Garry's Mod
85 stars 24 forks source link

Add a `PostHTTPRequest` hook #1700

Open FlorianLeChat opened 4 years ago

FlorianLeChat commented 4 years ago

It would be cool to have a hook that lets you know which requests are made with Gmod's HTTP function. This will avoid making another detour (or editing the lua/includes/modules/http.lua file) and the purpose would be mainly for logging. Not for blocking requests.

A long discussion has already taken place here for those interested.

GitSparTV commented 4 years ago

As code_gs said:

Give me a legitimate usecase that isn't related to blocking requests

They will just prevent it from being ran by returning in their own custom hook Or detouring your checks

viral32111 commented 4 years ago

From what I've seen, detouring has always been the way to do this and will likely continue be the way, especially for addons that log code execution. I personally don't really see the use in having a hook callback just for calling a single function. If this gets passed then people will end up suggesting hook callbacks for other functions and at that point you may aswell just be suggesting to add an OnFunctionCalled hook, which will inevitably lead to shit like OnVariableAssigned, OnStatementComparison, etc :/

GitSparTV commented 4 years ago

I think this hook doesn't have usage. Instead a command line parameter should be added -loghttp that will log all http requests, Logging should be done on C++ side to a file

Kefta commented 4 years ago

That would require you to do a random i/o access on the logging file everytime you want to see if HTTP was used though. There is a legitimate use for logging data in Lua on demand, there's just no use for a PreHTTP hook.

GitSparTV commented 4 years ago

That would require you to do a random i/o access on the logging file everytime you want to see if HTTP was used though.

This is the point, if you want to log http, turn it on for a few days and then remove.

Kefta commented 4 years ago

That's convoluted when there could just be a hook to get the results as soon as they're sent off. That way addons can log it however they want.

shadowscion commented 4 years ago

Give me a legitimate usecase that isn't related to blocking requests

Gotta be honest, I'm curious as to why that isn't enough. With the number of random addons that use http for any reason, legitimate or not, it's shocking that there is not a commandline to block all requests.

ThatLing commented 4 years ago

Give me a legitimate usecase that isn't related to blocking requests

Gotta be honest, I'm curious as to why that isn't enough. With the number of random addons that use http for any reason, legitimate or not, it's shocking that there is not a commandline to block all requests.

How are you going to block all requests with a PostHTTPRequest hook?

FlorianLeChat commented 4 years ago

I updated the description of the issue to include that this hook was not intended to block requests because it would be run after sending the request.