Skip to content

Commit

Permalink
[#159] http2 부팅 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
myyrakle committed Dec 19, 2024
1 parent 2b8136f commit a61eacd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
31 changes: 22 additions & 9 deletions rupring/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ mod parse;

#[cfg(feature = "aws-lambda")]
use bootings::aws_lambda::LambdaRequestEvent;
use hyper::server::conn::http2;
use hyper_util::rt::TokioExecutor;
use tokio::time::error::Elapsed;
use tokio::time::Instant;
Expand All @@ -29,7 +28,6 @@ use std::sync::Arc;
use http_body_util::BodyExt;
use http_body_util::Full;
use hyper::body::Bytes;
use hyper::server::conn::http1;
use hyper::service::service_fn;
use hyper::StatusCode;
use hyper::{Request, Response};
Expand Down Expand Up @@ -196,13 +194,28 @@ pub async fn run_server(
}
});

if let Err(err) = http1::Builder::new()
.keep_alive(keep_alive)
// `service_fn` converts our function in a `Service`
.serve_connection(io, service)
.await
{
println!("Error serving connection: {:?}", err);
if http2_enabled {
let mut http_builder =
hyper_util::server::conn::auto::Builder::new(TokioExecutor::new());

http_builder.http2().enable_connect_protocol();

if let Err(err) = http_builder
.serve_connection_with_upgrades(io, service)
.await
{
println!("Error serving connection: {:?}", err);
}
} else {
let mut http_builder = hyper::server::conn::http1::Builder::new();

if keep_alive {
http_builder.keep_alive(keep_alive);
}

if let Err(err) = http_builder.serve_connection(io, service).await {
println!("Error serving connection: {:?}", err);
}
}
});
}
Expand Down
3 changes: 2 additions & 1 deletion rupring_example/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ server.compression.mime-types=application/json,application/xml,text/html,text/xm
server.compression.min-response-size=1024
server.compression.algorithm=gzip
server.request-timeout=3s
server.http1.keep-alive=false
server.http1.keep-alive=true
server.http2.enabled=true

0 comments on commit a61eacd

Please sign in to comment.