mirror of
https://github.com/DefectingCat/candy
synced 2025-07-15 16:51:34 +00:00
feat: add max body size support
This commit is contained in:
@ -11,11 +11,9 @@ timeout = 15
|
|||||||
# sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout ./html/selfsigned.key -out ./html/selfsigned.crt
|
# sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout ./html/selfsigned.key -out ./html/selfsigned.crt
|
||||||
certificate = "./html/selfsigned.crt"
|
certificate = "./html/selfsigned.crt"
|
||||||
certificate_key = "./html/selfsigned.key"
|
certificate_key = "./html/selfsigned.key"
|
||||||
|
|
||||||
# Add custom headers to response
|
# Add custom headers to response
|
||||||
[host.headers]
|
[host.headers]
|
||||||
X-Powered-By = "candy"
|
X-Powered-By = "candy"
|
||||||
|
|
||||||
# Routes for virtual host
|
# Routes for virtual host
|
||||||
[[host.route]]
|
[[host.route]]
|
||||||
# Route location
|
# Route location
|
||||||
@ -28,7 +26,6 @@ root = "./html"
|
|||||||
index = ["index.html"]
|
index = ["index.html"]
|
||||||
# List directory
|
# List directory
|
||||||
auto_index = true
|
auto_index = true
|
||||||
|
|
||||||
# Custom 500 page
|
# Custom 500 page
|
||||||
[host.route.error_page]
|
[host.route.error_page]
|
||||||
status = 500
|
status = 500
|
||||||
@ -38,8 +35,11 @@ page = "500.html"
|
|||||||
status = 404
|
status = 404
|
||||||
page = "404.html"
|
page = "404.html"
|
||||||
|
|
||||||
|
# Reverse proxy
|
||||||
[[host.route]]
|
[[host.route]]
|
||||||
location = "/proxy/"
|
location = "/proxy/"
|
||||||
proxy_pass = "http://localhost:3000/"
|
proxy_pass = "http://localhost:3000/"
|
||||||
# Timeout for connect to upstream
|
# Timeout for connect to upstream
|
||||||
proxy_timeout = 10
|
proxy_timeout = 10
|
||||||
|
# Client request max body size (bytes)
|
||||||
|
max_body_size = 2048
|
||||||
|
@ -40,6 +40,8 @@ pub struct SettingRoute {
|
|||||||
/// Timeout for connect to upstream
|
/// Timeout for connect to upstream
|
||||||
#[serde(default = "upstream_timeout_default")]
|
#[serde(default = "upstream_timeout_default")]
|
||||||
pub proxy_timeout: u16,
|
pub proxy_timeout: u16,
|
||||||
|
/// Request max body size (bytes)
|
||||||
|
pub max_body_size: Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Host routes
|
/// Host routes
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use std::{net::SocketAddr, sync::LazyLock, time::Duration};
|
use std::{net::SocketAddr, sync::LazyLock, time::Duration};
|
||||||
|
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use axum::{Router, middleware, routing::get};
|
use axum::{Router, extract::DefaultBodyLimit, middleware, routing::get};
|
||||||
use axum_server::{Handle, tls_rustls::RustlsConfig};
|
use axum_server::{Handle, tls_rustls::RustlsConfig};
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
use tower::ServiceBuilder;
|
use tower::ServiceBuilder;
|
||||||
@ -46,6 +46,13 @@ pub async fn make_server(host: SettingHost) -> anyhow::Result<()> {
|
|||||||
// register wildcard path /doc/*
|
// register wildcard path /doc/*
|
||||||
let route_path = format!("{}{{*path}}", host_route.location);
|
let route_path = format!("{}{{*path}}", host_route.location);
|
||||||
router = router.route(route_path.as_ref(), get(reverse_proxy::serve));
|
router = router.route(route_path.as_ref(), get(reverse_proxy::serve));
|
||||||
|
// Set request max body size
|
||||||
|
if let Some(max_body_size) = host_route.max_body_size {
|
||||||
|
router = router.layer(DefaultBodyLimit::max(max_body_size as usize));
|
||||||
|
}
|
||||||
|
// if host_route.root.is_some() {
|
||||||
|
// router = router.layer(DefaultBodyLimit::max())
|
||||||
|
// }
|
||||||
// save route path to map
|
// save route path to map
|
||||||
{
|
{
|
||||||
host_to_save
|
host_to_save
|
||||||
@ -58,6 +65,10 @@ pub async fn make_server(host: SettingHost) -> anyhow::Result<()> {
|
|||||||
warn!("root field not found for route: {:?}", host_route.location);
|
warn!("root field not found for route: {:?}", host_route.location);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
// Set request max body size
|
||||||
|
if let Some(max_body_size) = host_route.max_body_size {
|
||||||
|
router = router.layer(DefaultBodyLimit::max(max_body_size as usize));
|
||||||
|
}
|
||||||
// resister with location
|
// resister with location
|
||||||
// location = "/doc"
|
// location = "/doc"
|
||||||
// route: GET /doc/*
|
// route: GET /doc/*
|
||||||
|
Reference in New Issue
Block a user