Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions crates/trigger-http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ pub struct CliArgs {
#[clap(long, env = "SPIN_TLS_KEY", requires = "tls-cert")]
pub tls_key: Option<PathBuf>,

/// Sets the maximum buffer size (in bytes) for the HTTP connection. The minimum value allowed is 8192.
#[clap(long, env = "SPIN_HTTP1_MAX_BUF_SIZE")]
pub http1_max_buf_size: Option<usize>,

#[clap(long = "find-free-port")]
pub find_free_port: bool,
}
Expand All @@ -78,6 +82,7 @@ pub struct HttpTrigger {
listen_addr: SocketAddr,
tls_config: Option<TlsConfig>,
find_free_port: bool,
http1_max_buf_size: Option<usize>,
}

impl<F: RuntimeFactors> Trigger<F> for HttpTrigger {
Expand All @@ -88,12 +93,14 @@ impl<F: RuntimeFactors> Trigger<F> for HttpTrigger {

fn new(cli_args: Self::CliArgs, app: &spin_app::App) -> anyhow::Result<Self> {
let find_free_port = cli_args.find_free_port;
let http1_max_buf_size = cli_args.http1_max_buf_size;

Self::new(
app,
cli_args.address,
cli_args.into_tls_config(),
find_free_port,
http1_max_buf_size,
)
}

Expand All @@ -117,13 +124,15 @@ impl HttpTrigger {
listen_addr: SocketAddr,
tls_config: Option<TlsConfig>,
find_free_port: bool,
http1_max_buf_size: Option<usize>,
) -> anyhow::Result<Self> {
Self::validate_app(app)?;

Ok(Self {
listen_addr,
tls_config,
find_free_port,
http1_max_buf_size,
})
}

Expand All @@ -136,12 +145,14 @@ impl HttpTrigger {
listen_addr,
tls_config,
find_free_port,
http1_max_buf_size,
} = self;
let server = Arc::new(HttpServer::new(
listen_addr,
tls_config,
find_free_port,
trigger_app,
http1_max_buf_size,
)?);
Ok(server)
}
Expand Down
12 changes: 11 additions & 1 deletion crates/trigger-http/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ pub struct HttpServer<F: RuntimeFactors> {
listen_addr: SocketAddr,
/// The TLS configuration for the server.
tls_config: Option<TlsConfig>,
/// The maximum buffer size for an HTTP1 connection.
http1_max_buf_size: Option<usize>,
/// Whether to find a free port if the specified port is already in use.
find_free_port: bool,
/// Request router.
Expand All @@ -77,6 +79,7 @@ impl<F: RuntimeFactors> HttpServer<F> {
tls_config: Option<TlsConfig>,
find_free_port: bool,
trigger_app: TriggerApp<F>,
http1_max_buf_size: Option<usize>,
) -> anyhow::Result<Self> {
// This needs to be a vec before building the router to handle duplicate routes
let component_trigger_configs = trigger_app
Expand Down Expand Up @@ -139,6 +142,7 @@ impl<F: RuntimeFactors> HttpServer<F> {
find_free_port,
router,
trigger_app,
http1_max_buf_size,
component_trigger_configs,
component_handler_types,
})
Expand Down Expand Up @@ -491,7 +495,13 @@ impl<F: RuntimeFactors> HttpServer<F> {
client_addr: SocketAddr,
) {
task::spawn(async move {
if let Err(err) = Builder::new(TokioExecutor::new())
let mut server_builder = Builder::new(TokioExecutor::new());

if let Some(http1_max_buf_size) = self.http1_max_buf_size {
server_builder.http1().max_buf_size(http1_max_buf_size);
}

if let Err(err) = server_builder
.serve_connection(
TokioIo::new(stream),
service_fn(move |request| {
Expand Down
2 changes: 1 addition & 1 deletion tests/testing-framework/src/runtimes/in_process_spin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ async fn initialize_trigger(
.await?;

let app = spin_app::App::new("my-app", locked_app);
let trigger = HttpTrigger::new(&app, "127.0.0.1:80".parse().unwrap(), None, false)?;
let trigger = HttpTrigger::new(&app, "127.0.0.1:80".parse().unwrap(), None, false, None)?;
let mut builder = TriggerAppBuilder::<_, FactorsBuilder>::new(trigger);
let trigger_app = builder
.build(
Expand Down