Skip to content

Commit

Permalink
Add a convar to produce an error on URL block
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonsturgeon committed Dec 29, 2024
1 parent 6b399ee commit c78cdd5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lua/cfc_http_restrictions/shared/logging.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ local COLORS = {
local shouldLogAllows = CreateConVar( "cfc_http_restrictions_log_allows", "1", FCVAR_ARCHIVE, "Should the HTTP restrictions log allowed HTTP requests?", 0, 1 )
local shouldLogBlocks = CreateConVar( "cfc_http_restrictions_log_blocks", "1", FCVAR_ARCHIVE, "Should the HTTP restrictions log blocked HTTP requests?", 0, 1 )
local verboseLogging = CreateConVar( "cfc_http_restrictions_log_verbose", "0", FCVAR_ARCHIVE, "Should the HTTP restrictions log include verbose messages?", 0, 1 )
local errorOnBlocks = CreateConVar( "cfc_http_restrictions_error_on_blocks", "0", FCVAR_ARCHIVE, "Should the HTTP restrictions produce a Lua error on blocked HTTP requests?", 0, 1 )

local statusColors = {
ALLOWED = COLORS.GREEN,
Expand Down Expand Up @@ -45,6 +46,10 @@ function CFCHTTP.LogRequest( input )
if not shouldLogAllows:GetBool() and requestStatus == "ALLOWED" then return end
if not shouldLogBlocks:GetBool() and requestStatus == "BLOCKED" then return end

if requestStatus == "BLOCKED" and errorOnBlocks:GetBool() then
ErrorNoHaltWithStack( "Blocked HTTP request to: " .. url )
end

MsgC(
requestColor, requestStatus,
COLORS.GREY, ": ",
Expand Down
1 change: 0 additions & 1 deletion lua/cfc_http_restrictions/wraps/http.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ end

local function wrapHTTP()
_HTTP = _HTTP or HTTP
print( "HTTP wrapped, original function at '_G._HTTP'" )

HTTP = function( req )
local options = CFCHTTP.GetOptionsForURL( req.url )
Expand Down

0 comments on commit c78cdd5

Please # to comment.