From eb4dff419cfc889f3639b33579782692e128629d Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Thu, 3 Apr 2025 13:47:01 -0700 Subject: [PATCH 1/2] fix: compatibility with older nginx versions * `NGX_HTTP_CONNECT` was added in 1.21.1 * `ngx_http_v2_module` was not exposed by default until nginx/nginx@aefd862a --- build.rs | 27 ++++++++++++++++++--------- src/http/conf.rs | 6 +++--- src/http/request.rs | 33 +++++++++++++++++---------------- 3 files changed, 38 insertions(+), 28 deletions(-) diff --git a/build.rs b/build.rs index 763ec1b..76eec3c 100644 --- a/build.rs +++ b/build.rs @@ -34,15 +34,24 @@ fn main() { } // Generate cfg values for version checks - // println!("cargo::rustc-check-cfg=cfg(nginx1_27_0)"); - // println!("cargo::rerun-if-env-changed=DEP_NGINX_VERSION_NUMBER"); - // if let Ok(version) = std::env::var("DEP_NGINX_VERSION_NUMBER") { - // let version: u64 = version.parse().unwrap(); - // - // if version >= 1_027_000 { - // println!("cargo::rustc-cfg=nginx1_27_0"); - // } - // } + const VERSION_CHECKS: &[(u64, &str)] = &[ + // + (1_021_001, "nginx1_21_1"), + (1_025_001, "nginx1_25_1"), + ]; + VERSION_CHECKS + .iter() + .for_each(|check| println!("cargo::rustc-check-cfg=cfg({})", check.1)); + println!("cargo::rerun-if-env-changed=DEP_NGINX_VERSION_NUMBER"); + if let Ok(version) = std::env::var("DEP_NGINX_VERSION_NUMBER") { + let version: u64 = version.parse().unwrap(); + + for check in VERSION_CHECKS { + if version >= check.0 { + println!("cargo::rustc-cfg={}", check.1); + } + } + } // Generate required compiler flags if cfg!(target_os = "macos") { diff --git a/src/http/conf.rs b/src/http/conf.rs index b26ecd5..7f467d2 100644 --- a/src/http/conf.rs +++ b/src/http/conf.rs @@ -240,7 +240,7 @@ mod upstream { pub use upstream::NgxHttpUpstreamModule; -#[cfg(ngx_feature = "http_v2")] +#[cfg(all(nginx1_25_1, ngx_feature = "http_v2"))] mod http_v2 { use crate::ffi::{ngx_http_v2_module, ngx_http_v2_srv_conf_t}; @@ -256,8 +256,8 @@ mod http_v2 { type ServerConf = ngx_http_v2_srv_conf_t; } } - -#[cfg(ngx_feature = "http_v2")] +// ngx_http_v2_module was not exposed by default until aefd862a +#[cfg(all(nginx1_25_1, ngx_feature = "http_v2"))] pub use http_v2::NgxHttpV2Module; #[cfg(ngx_feature = "http_v3")] diff --git a/src/http/request.rs b/src/http/request.rs index a9a66fc..9bab677 100644 --- a/src/http/request.rs +++ b/src/http/request.rs @@ -557,22 +557,23 @@ impl Method { fn from_ngx(t: ngx_uint_t) -> Method { let t = t as _; match t { - NGX_HTTP_GET => Method(MethodInner::Get), - NGX_HTTP_HEAD => Method(MethodInner::Head), - NGX_HTTP_POST => Method(MethodInner::Post), - NGX_HTTP_PUT => Method(MethodInner::Put), - NGX_HTTP_DELETE => Method(MethodInner::Delete), - NGX_HTTP_MKCOL => Method(MethodInner::Mkcol), - NGX_HTTP_COPY => Method(MethodInner::Copy), - NGX_HTTP_MOVE => Method(MethodInner::Move), - NGX_HTTP_OPTIONS => Method(MethodInner::Options), - NGX_HTTP_PROPFIND => Method(MethodInner::Propfind), - NGX_HTTP_PROPPATCH => Method(MethodInner::Proppatch), - NGX_HTTP_LOCK => Method(MethodInner::Lock), - NGX_HTTP_UNLOCK => Method(MethodInner::Unlock), - NGX_HTTP_PATCH => Method(MethodInner::Patch), - NGX_HTTP_TRACE => Method(MethodInner::Trace), - NGX_HTTP_CONNECT => Method(MethodInner::Connect), + crate::ffi::NGX_HTTP_GET => Method(MethodInner::Get), + crate::ffi::NGX_HTTP_HEAD => Method(MethodInner::Head), + crate::ffi::NGX_HTTP_POST => Method(MethodInner::Post), + crate::ffi::NGX_HTTP_PUT => Method(MethodInner::Put), + crate::ffi::NGX_HTTP_DELETE => Method(MethodInner::Delete), + crate::ffi::NGX_HTTP_MKCOL => Method(MethodInner::Mkcol), + crate::ffi::NGX_HTTP_COPY => Method(MethodInner::Copy), + crate::ffi::NGX_HTTP_MOVE => Method(MethodInner::Move), + crate::ffi::NGX_HTTP_OPTIONS => Method(MethodInner::Options), + crate::ffi::NGX_HTTP_PROPFIND => Method(MethodInner::Propfind), + crate::ffi::NGX_HTTP_PROPPATCH => Method(MethodInner::Proppatch), + crate::ffi::NGX_HTTP_LOCK => Method(MethodInner::Lock), + crate::ffi::NGX_HTTP_UNLOCK => Method(MethodInner::Unlock), + crate::ffi::NGX_HTTP_PATCH => Method(MethodInner::Patch), + crate::ffi::NGX_HTTP_TRACE => Method(MethodInner::Trace), + #[cfg(nginx1_21_1)] + crate::ffi::NGX_HTTP_CONNECT => Method(MethodInner::Connect), _ => Method(MethodInner::Unknown), } } From 06f8ae7f38fcb4310bdd9c22b27e66d9742f0649 Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Thu, 3 Apr 2025 13:57:48 -0700 Subject: [PATCH 2/2] chore: fix `clippy::double-ended-iterator-last` --- nginx-sys/build/vendored.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nginx-sys/build/vendored.rs b/nginx-sys/build/vendored.rs index de4289e..57286c3 100644 --- a/nginx-sys/build/vendored.rs +++ b/nginx-sys/build/vendored.rs @@ -364,7 +364,7 @@ fn download(cache_dir: &Path, url: &str) -> Result> { // File does not exist or is zero bytes !file_path.exists() || file_path.metadata().is_ok_and(|m| m.len() < 1) } - let filename = url.split('/').last().unwrap(); + let filename = url.split('/').next_back().unwrap(); let file_path = cache_dir.join(filename); if proceed_with_download(&file_path) { println!("Downloading: {} -> {}", url, file_path.display());