mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-06-20 07:32:40 +02:00
feat: use a in memory map to count requests for ips and log the n most active each hour
This commit is contained in:
parent
023ea17492
commit
b22d3665a9
7 changed files with 74 additions and 20 deletions
|
@ -141,7 +141,8 @@ func TestMergeConfigShouldReplaceAllExistingValuesGivenAllArgsExist(t *testing.T
|
|||
HttpPort: 80,
|
||||
HttpServerEnabled: false,
|
||||
UseProxyProtocol: false,
|
||||
LogEveryRequest: false,
|
||||
LogMostActiveIps: false,
|
||||
MostActiveIpCount: 10,
|
||||
MainDomain: "original",
|
||||
RawDomain: "original",
|
||||
PagesBranches: []string{"original"},
|
||||
|
@ -183,7 +184,8 @@ func TestMergeConfigShouldReplaceAllExistingValuesGivenAllArgsExist(t *testing.T
|
|||
HttpPort: 443,
|
||||
HttpServerEnabled: true,
|
||||
UseProxyProtocol: true,
|
||||
LogEveryRequest: true,
|
||||
LogMostActiveIps: true,
|
||||
MostActiveIpCount: 42,
|
||||
MainDomain: "changed",
|
||||
RawDomain: "changed",
|
||||
PagesBranches: []string{"changed"},
|
||||
|
@ -232,7 +234,7 @@ func TestMergeConfigShouldReplaceAllExistingValuesGivenAllArgsExist(t *testing.T
|
|||
"--http-port", "443",
|
||||
"--enable-http-server",
|
||||
"--use-proxy-protocol",
|
||||
"--log-every-request",
|
||||
"--log-most-active-ips", "42",
|
||||
// Forge
|
||||
"--forge-root", "changed",
|
||||
"--forge-api-token", "changed",
|
||||
|
@ -284,7 +286,8 @@ func TestMergeServerConfigShouldReplaceAllExistingValuesGivenAllArgsExist(t *tes
|
|||
HttpPort: 80,
|
||||
HttpServerEnabled: false,
|
||||
UseProxyProtocol: false,
|
||||
LogEveryRequest: false,
|
||||
LogMostActiveIps: false,
|
||||
MostActiveIpCount: 10,
|
||||
MainDomain: "original",
|
||||
RawDomain: "original",
|
||||
AllowedCorsDomains: []string{"original"},
|
||||
|
@ -299,7 +302,8 @@ func TestMergeServerConfigShouldReplaceAllExistingValuesGivenAllArgsExist(t *tes
|
|||
HttpPort: 443,
|
||||
HttpServerEnabled: true,
|
||||
UseProxyProtocol: true,
|
||||
LogEveryRequest: true,
|
||||
LogMostActiveIps: true,
|
||||
MostActiveIpCount: 21,
|
||||
MainDomain: "changed",
|
||||
RawDomain: "changed",
|
||||
AllowedCorsDomains: fixArrayFromCtx(ctx, "allowed-cors-domains", []string{"changed"}),
|
||||
|
@ -320,7 +324,7 @@ func TestMergeServerConfigShouldReplaceAllExistingValuesGivenAllArgsExist(t *tes
|
|||
"--http-port", "443",
|
||||
"--enable-http-server",
|
||||
"--use-proxy-protocol",
|
||||
"--log-every-request",
|
||||
"--log-most-active-ips", "21",
|
||||
},
|
||||
)
|
||||
}
|
||||
|
@ -342,7 +346,10 @@ func TestMergeServerConfigShouldReplaceOnlyOneValueExistingValueGivenOnlyOneArgE
|
|||
{args: []string{"--allowed-cors-domains", "changed"}, callback: func(sc *ServerConfig) { sc.AllowedCorsDomains = []string{"changed"} }},
|
||||
{args: []string{"--blacklisted-paths", "changed"}, callback: func(sc *ServerConfig) { sc.BlacklistedPaths = []string{"changed"} }},
|
||||
{args: []string{"--use-proxy-protocol"}, callback: func(sc *ServerConfig) { sc.UseProxyProtocol = true }},
|
||||
{args: []string{"--log-every-request"}, callback: func(sc *ServerConfig) { sc.LogEveryRequest = true }},
|
||||
{args: []string{"--log-most-active-ips", "42"}, callback: func(sc *ServerConfig) {
|
||||
sc.LogMostActiveIps = true
|
||||
sc.MostActiveIpCount = 42
|
||||
}},
|
||||
}
|
||||
|
||||
for _, pair := range testValuePairs {
|
||||
|
@ -360,7 +367,8 @@ func TestMergeServerConfigShouldReplaceOnlyOneValueExistingValueGivenOnlyOneArgE
|
|||
AllowedCorsDomains: []string{"original"},
|
||||
BlacklistedPaths: []string{"original"},
|
||||
UseProxyProtocol: false,
|
||||
LogEveryRequest: false,
|
||||
LogMostActiveIps: false,
|
||||
MostActiveIpCount: 10,
|
||||
}
|
||||
|
||||
expectedConfig := cfg
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue