Skip to content

Commit 448abc0

Browse files
committed
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
1 parent b6e80fc commit 448abc0

File tree

3 files changed

+38
-28
lines changed

3 files changed

+38
-28
lines changed

build.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,24 @@ fn main() {
3434
}
3535

3636
// Generate cfg values for version checks
37-
// println!("cargo::rustc-check-cfg=cfg(nginx1_27_0)");
38-
// println!("cargo::rerun-if-env-changed=DEP_NGINX_VERSION_NUMBER");
39-
// if let Ok(version) = std::env::var("DEP_NGINX_VERSION_NUMBER") {
40-
// let version: u64 = version.parse().unwrap();
41-
//
42-
// if version >= 1_027_000 {
43-
// println!("cargo::rustc-cfg=nginx1_27_0");
44-
// }
45-
// }
37+
const VERSION_CHECKS: &[(u64, &str)] = &[
38+
//
39+
(1_021_001, "nginx1_21_1"),
40+
(1_025_001, "nginx1_25_1"),
41+
];
42+
VERSION_CHECKS
43+
.iter()
44+
.for_each(|check| println!("cargo::rustc-check-cfg=cfg({})", check.1));
45+
println!("cargo::rerun-if-env-changed=DEP_NGINX_VERSION_NUMBER");
46+
if let Ok(version) = std::env::var("DEP_NGINX_VERSION_NUMBER") {
47+
let version: u64 = version.parse().unwrap();
48+
49+
for check in VERSION_CHECKS {
50+
if version >= check.0 {
51+
println!("cargo::rustc-cfg={}", check.1);
52+
}
53+
}
54+
}
4655

4756
// Generate required compiler flags
4857
if cfg!(target_os = "macos") {

src/http/conf.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ mod upstream {
240240

241241
pub use upstream::NgxHttpUpstreamModule;
242242

243-
#[cfg(ngx_feature = "http_v2")]
243+
#[cfg(all(nginx1_25_1, ngx_feature = "http_v2"))]
244244
mod http_v2 {
245245
use crate::ffi::{ngx_http_v2_module, ngx_http_v2_srv_conf_t};
246246

@@ -256,8 +256,8 @@ mod http_v2 {
256256
type ServerConf = ngx_http_v2_srv_conf_t;
257257
}
258258
}
259-
260-
#[cfg(ngx_feature = "http_v2")]
259+
// ngx_http_v2_module was not exposed by default until aefd862a
260+
#[cfg(all(nginx1_25_1, ngx_feature = "http_v2"))]
261261
pub use http_v2::NgxHttpV2Module;
262262

263263
#[cfg(ngx_feature = "http_v3")]

src/http/request.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -557,22 +557,23 @@ impl Method {
557557
fn from_ngx(t: ngx_uint_t) -> Method {
558558
let t = t as _;
559559
match t {
560-
NGX_HTTP_GET => Method(MethodInner::Get),
561-
NGX_HTTP_HEAD => Method(MethodInner::Head),
562-
NGX_HTTP_POST => Method(MethodInner::Post),
563-
NGX_HTTP_PUT => Method(MethodInner::Put),
564-
NGX_HTTP_DELETE => Method(MethodInner::Delete),
565-
NGX_HTTP_MKCOL => Method(MethodInner::Mkcol),
566-
NGX_HTTP_COPY => Method(MethodInner::Copy),
567-
NGX_HTTP_MOVE => Method(MethodInner::Move),
568-
NGX_HTTP_OPTIONS => Method(MethodInner::Options),
569-
NGX_HTTP_PROPFIND => Method(MethodInner::Propfind),
570-
NGX_HTTP_PROPPATCH => Method(MethodInner::Proppatch),
571-
NGX_HTTP_LOCK => Method(MethodInner::Lock),
572-
NGX_HTTP_UNLOCK => Method(MethodInner::Unlock),
573-
NGX_HTTP_PATCH => Method(MethodInner::Patch),
574-
NGX_HTTP_TRACE => Method(MethodInner::Trace),
575-
NGX_HTTP_CONNECT => Method(MethodInner::Connect),
560+
crate::ffi::NGX_HTTP_GET => Method(MethodInner::Get),
561+
crate::ffi::NGX_HTTP_HEAD => Method(MethodInner::Head),
562+
crate::ffi::NGX_HTTP_POST => Method(MethodInner::Post),
563+
crate::ffi::NGX_HTTP_PUT => Method(MethodInner::Put),
564+
crate::ffi::NGX_HTTP_DELETE => Method(MethodInner::Delete),
565+
crate::ffi::NGX_HTTP_MKCOL => Method(MethodInner::Mkcol),
566+
crate::ffi::NGX_HTTP_COPY => Method(MethodInner::Copy),
567+
crate::ffi::NGX_HTTP_MOVE => Method(MethodInner::Move),
568+
crate::ffi::NGX_HTTP_OPTIONS => Method(MethodInner::Options),
569+
crate::ffi::NGX_HTTP_PROPFIND => Method(MethodInner::Propfind),
570+
crate::ffi::NGX_HTTP_PROPPATCH => Method(MethodInner::Proppatch),
571+
crate::ffi::NGX_HTTP_LOCK => Method(MethodInner::Lock),
572+
crate::ffi::NGX_HTTP_UNLOCK => Method(MethodInner::Unlock),
573+
crate::ffi::NGX_HTTP_PATCH => Method(MethodInner::Patch),
574+
crate::ffi::NGX_HTTP_TRACE => Method(MethodInner::Trace),
575+
#[cfg(nginx1_21_1)]
576+
crate::ffi::NGX_HTTP_CONNECT => Method(MethodInner::Connect),
576577
_ => Method(MethodInner::Unknown),
577578
}
578579
}

0 commit comments

Comments
 (0)