add gzip_chance
This commit is contained in:
parent
2a8bbffb43
commit
d774b5d109
2 changed files with 27 additions and 7 deletions
|
|
@ -25,6 +25,7 @@ timeout = 20 # seconds to keep returning fails to the same ip
|
|||
# used when data = "generated"
|
||||
[fail_response.generated]
|
||||
gzip = true # gzip the response for a zip bomb experience
|
||||
gzip_chance = 100 # in percent, chance that gzip will actually be used if its enabled above
|
||||
auto_gzip = true # only gzip if client accepts it, otherwise send raw
|
||||
length = "15M" # length of the response in bytes, or "none" for no length header (extra evil but maybe unsupported). 15MB is the max that chatgpt will parse
|
||||
content-type = "text/html" # so AIs actually ingest it
|
||||
|
|
|
|||
|
|
@ -30,13 +30,7 @@ impl ConnectionState for GeneratedBullshitResponder {
|
|||
"Content-Type",
|
||||
CONFIG["fail_response.generated.content-type"].str(),
|
||||
);
|
||||
if CONFIG["fail_response.generated.gzip"].boolean()
|
||||
&& (!CONFIG["fail_response.generated.auto_gzip"].boolean()
|
||||
|| connection
|
||||
.headers
|
||||
.get("Accept-Encoding")
|
||||
.is_some_and(|x| x.contains("gzip")))
|
||||
{
|
||||
if should_gzip(connection) {
|
||||
response_writer = response_writer
|
||||
.with_header("Content-Encoding", "gzip")
|
||||
.with_body(get_body());
|
||||
|
|
@ -179,3 +173,28 @@ fn get_begin() -> Vec<u8> {
|
|||
BEGIN.clone()
|
||||
}
|
||||
}
|
||||
|
||||
fn should_gzip(connection: &Connection) -> bool {
|
||||
let gzip_enabled = CONFIG["fail_response.generated.gzip"].boolean();
|
||||
let auto_gzip = CONFIG["fail_response.generated.auto_gzip"].boolean();
|
||||
let gzip_chance_percent = CONFIG["fail_response.generated.gzip_chance"].num() as u128;
|
||||
|
||||
if !gzip_enabled {
|
||||
return false;
|
||||
}
|
||||
|
||||
if auto_gzip
|
||||
&& !connection
|
||||
.headers
|
||||
.get("Accept-Encoding")
|
||||
.is_some_and(|x| x.contains("gzip"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if SystemTime::UNIX_EPOCH.elapsed().unwrap().as_micros() % 100 > gzip_chance_percent {
|
||||
return false;
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue