I have a small Rust program that formats MySQL queries, but I found it failing on bigger queries, returning
Urlencoded payload size is bigger than allowed (default: 256kB)
I'm using actix web, which looks like this
use actix_web::{
web, App, HttpResponse, HttpServer, Result,
};
#[derive(Deserialize)]
pub struct MyParams {
q: String,
}
fn index(params: web::Form<MyParams>) -> Result<HttpResponse> {
Ok(HttpResponse::Ok()
.content_type("text/html; charset=utf-8")
.body("test"))
// .body(mysql_format2(¶ms.q[..])))
}
fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new().service(
web::resource("/")
.route(web::post().to(index))
)
})
.bind("127.0.0.1:48627")?
.run()
}
And the PHP script calling this looks like
$this->FormattedMySQL = str_repeat("make a big query ", 1024*256);
$query = http_build_query([
'q' => $this->FormattedMySQL,
]);
// if I change this to 16385 (+1)
// then it breaks and returns that error
$query = substr($query, 0, 16384);
if ($this->FormatMySQL && strlen($query) <= 262144) {
try {
$this->VerbosePrint('formatting');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, MYSQL_FORMAT_ENDPOINT);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$this->FormattedMySQL = curl_exec($ch);
curl_close($ch);
} catch (Exception $_) { }
}
What am I missing, or why does this seem to be throwing this error for 16kB instead of 256kB?
I see that it's also possible to set the Payload
config but I'm not totally sure how/where to apply this in my existing code.