Skip to content

Commit

Permalink
Merge pull request #206 from myyrakle/feat/#197
Browse files Browse the repository at this point in the history
[#197] features flag 추가: http2
  • Loading branch information
myyrakle authored Dec 28, 2024
2 parents 4d5abe7 + dcf6888 commit 73a6a0b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
1 change: 1 addition & 0 deletions rupring/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ default = []
full = ["aws-lambda"]
aws-lambda = []
tls = ["tokio-rustls", "rustls-pemfile", "rustls"]
http2 = []
12 changes: 2 additions & 10 deletions rupring/src/application_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
| server.thread.limit | The thread limit to use. | None(max) |
| server.request-timeout | The request timeout. (300 = 300 millisecond, 3s = 3 second, 2m = 2 minute) | No Timeout |
| server.http1.keep-alive | Whether to keep-alive for HTTP/1. (false=disable, true=enable) | false |
| server.http2.enabled | Whether to enable HTTP/2. | false |
| server.ssl.key | The SSL key file. (SSL is enabled by feature="tls") | None |
| server.ssl.cert | The SSL cert file. (SSL is enabled by feature="tls") | None |
| banner.enabled | Whether to enable the banner. | true |
Expand Down Expand Up @@ -168,13 +167,11 @@ impl Default for Http1 {
}

#[derive(Debug, PartialEq, Clone)]
pub struct Http2 {
pub enabled: bool,
}
pub struct Http2 {}

impl Default for Http2 {
fn default() -> Self {
Http2 { enabled: false }
Http2 {}
}
}

Expand Down Expand Up @@ -337,11 +334,6 @@ impl ApplicationProperties {
server.http1.keep_alive = value;
}
}
"server.http2.enabled" => {
if let Ok(value) = value.parse::<bool>() {
server.http2.enabled = value;
}
}
"server.ssl.key" => {
server.ssl.key = value.to_string();
}
Expand Down
18 changes: 14 additions & 4 deletions rupring/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use bootings::aws_lambda::LambdaRequestEvent;

#[cfg(feature = "tls")]
use bootings::tls;
use hyper_util::rt::TokioExecutor;
use tokio::time::error::Elapsed;
use tokio::time::Instant;

Expand Down Expand Up @@ -84,8 +83,8 @@ pub async fn run_server(
);
}

#[cfg(not(feature = "http2"))]
let keep_alive = application_properties.server.http1.keep_alive.to_owned();
let http2_enabled = application_properties.server.http2.enabled.to_owned();

#[cfg(feature = "tls")]
let tls_acceptor = {
Expand All @@ -94,6 +93,11 @@ pub async fn run_server(
tls::new_tls_acceptor(&application_properties)?
};

#[cfg(feature = "http2")]
{
print_system_log(Level::Info, "HTTP/2 Enabled");
}

// 5. Main Server Loop
// Spawns a new async Task for each request.
loop {
Expand Down Expand Up @@ -219,7 +223,10 @@ pub async fn run_server(
#[cfg(not(feature = "tls"))]
let io = TokioIo::new(tcp_stream);

if http2_enabled {
#[cfg(feature = "http2")]
{
use hyper_util::rt::TokioExecutor;

let mut http_builder =
hyper_util::server::conn::auto::Builder::new(TokioExecutor::new());

Expand All @@ -231,7 +238,10 @@ pub async fn run_server(
{
println!("Error serving connection: {:?}", err);
}
} else {
}

#[cfg(not(feature = "http2"))]
{
let mut http_builder = hyper::server::conn::http1::Builder::new();

if keep_alive {
Expand Down

0 comments on commit 73a6a0b

Please sign in to comment.