Skip to content

Commit 1d6f288

Browse files
feat: configurable payload limit (#210)
1 parent 6fa3c6a commit 1d6f288

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,18 @@ Options:
223223
[default: /tmp/text-embeddings-inference-server]
224224
225225
--huggingface-hub-cache <HUGGINGFACE_HUB_CACHE>
226-
The location of the huggingface hub cache. Used to override the location if you want to provide a mounted disk
227-
for instance
226+
The location of the huggingface hub cache. Used to override the location if you want to provide a mounted disk for instance
228227
229228
[env: HUGGINGFACE_HUB_CACHE=/data]
230229
230+
--payload-limit <PAYLOAD_LIMIT>
231+
Payload size limit in bytes
232+
233+
Default is 2MB
234+
235+
[env: PAYLOAD_LIMIT=]
236+
[default: 2000000]
237+
231238
--json-output
232239
Outputs the logs in JSON format (useful for telemetry)
233240

router/src/http/server.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
};
1313
use ::http::HeaderMap;
1414
use anyhow::Context;
15-
use axum::extract::Extension;
15+
use axum::extract::{DefaultBodyLimit, Extension};
1616
use axum::http::HeaderValue;
1717
use axum::http::{Method, StatusCode};
1818
use axum::routing::{get, post};
@@ -1262,6 +1262,7 @@ pub async fn run(
12621262
info: Info,
12631263
addr: SocketAddr,
12641264
prom_builder: PrometheusBuilder,
1265+
payload_limit: usize,
12651266
cors_allow_origin: Option<Vec<String>>,
12661267
) -> Result<(), anyhow::Error> {
12671268
// OpenAPI documentation
@@ -1370,7 +1371,8 @@ pub async fn run(
13701371
};
13711372

13721373
// Create router
1373-
let base_routes = Router::new()
1374+
let mut app = Router::new()
1375+
.layer(DefaultBodyLimit::max(payload_limit))
13741376
.merge(SwaggerUi::new("/docs").url("/api-doc/openapi.json", doc))
13751377
// Base routes
13761378
.route("/info", get(get_model_info))
@@ -1393,8 +1395,6 @@ pub async fn run(
13931395
// Prometheus metrics route
13941396
.route("/metrics", get(metrics));
13951397

1396-
let mut app = Router::new().merge(base_routes);
1397-
13981398
// Set default routes
13991399
app = match &info.model_type {
14001400
ModelType::Classifier(_) => {

router/src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub async fn run(
5656
port: u16,
5757
uds_path: Option<String>,
5858
huggingface_hub_cache: Option<String>,
59+
payload_limit: usize,
5960
otlp_endpoint: Option<String>,
6061
cors_allow_origin: Option<Vec<String>>,
6162
) -> Result<()> {
@@ -268,7 +269,15 @@ pub async fn run(
268269
#[cfg(feature = "http")]
269270
{
270271
let server = tokio::spawn(async move {
271-
http::server::run(infer, info, addr, prom_builder, cors_allow_origin).await
272+
http::server::run(
273+
infer,
274+
info,
275+
addr,
276+
prom_builder,
277+
payload_limit,
278+
cors_allow_origin,
279+
)
280+
.await
272281
});
273282
tracing::info!("Ready");
274283
server.await??;

router/src/main.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ struct Args {
9696
#[clap(long, env)]
9797
huggingface_hub_cache: Option<String>,
9898

99+
/// Payload size limit in bytes
100+
///
101+
/// Default is 2MB
102+
#[clap(default_value = "2000000", long, env)]
103+
payload_limit: usize,
104+
99105
/// Outputs the logs in JSON format (useful for telemetry)
100106
#[clap(long, env)]
101107
json_output: bool,
@@ -136,6 +142,7 @@ async fn main() -> Result<()> {
136142
args.port,
137143
Some(args.uds_path),
138144
args.huggingface_hub_cache,
145+
args.payload_limit,
139146
args.otlp_endpoint,
140147
args.cors_allow_origin,
141148
)

0 commit comments

Comments
 (0)