Skip to content

Commit ef26134

Browse files
committed
refactor: changes to support edition = "2024"
this change set is created automatically by `cargo fix --edition --all`, then `cargo fmt --all`
1 parent e47e068 commit ef26134

24 files changed

+492
-385
lines changed

examples/async.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,21 @@ impl http::HttpModule for Module {
2424
}
2525

2626
unsafe extern "C" fn postconfiguration(cf: *mut ngx_conf_t) -> ngx_int_t {
27-
// SAFETY: this function is called with non-NULL cf always
28-
let cf = &mut *cf;
29-
let cmcf = NgxHttpCoreModule::main_conf_mut(cf).expect("http core main conf");
30-
31-
let h = ngx_array_push(
32-
&mut cmcf.phases[ngx_http_phases_NGX_HTTP_ACCESS_PHASE as usize].handlers,
33-
) as *mut ngx_http_handler_pt;
34-
if h.is_null() {
35-
return core::Status::NGX_ERROR.into();
27+
unsafe {
28+
// SAFETY: this function is called with non-NULL cf always
29+
let cf = &mut *cf;
30+
let cmcf = NgxHttpCoreModule::main_conf_mut(cf).expect("http core main conf");
31+
32+
let h = ngx_array_push(
33+
&mut cmcf.phases[ngx_http_phases_NGX_HTTP_ACCESS_PHASE as usize].handlers,
34+
) as *mut ngx_http_handler_pt;
35+
if h.is_null() {
36+
return core::Status::NGX_ERROR.into();
37+
}
38+
// set an Access phase handler
39+
*h = Some(async_access_handler);
40+
core::Status::NGX_OK.into()
3641
}
37-
// set an Access phase handler
38-
*h = Some(async_access_handler);
39-
core::Status::NGX_OK.into()
4042
}
4143
}
4244

examples/awssig.rs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,21 @@ impl HttpModule for Module {
1919
}
2020

2121
unsafe extern "C" fn postconfiguration(cf: *mut ngx_conf_t) -> ngx_int_t {
22-
// SAFETY: this function is called with non-NULL cf always
23-
let cf = &mut *cf;
24-
let cmcf = NgxHttpCoreModule::main_conf_mut(cf).expect("http core main conf");
25-
26-
let h = ngx_array_push(
27-
&mut cmcf.phases[ngx_http_phases_NGX_HTTP_PRECONTENT_PHASE as usize].handlers,
28-
) as *mut ngx_http_handler_pt;
29-
if h.is_null() {
30-
return core::Status::NGX_ERROR.into();
22+
unsafe {
23+
// SAFETY: this function is called with non-NULL cf always
24+
let cf = &mut *cf;
25+
let cmcf = NgxHttpCoreModule::main_conf_mut(cf).expect("http core main conf");
26+
27+
let h = ngx_array_push(
28+
&mut cmcf.phases[ngx_http_phases_NGX_HTTP_PRECONTENT_PHASE as usize].handlers,
29+
) as *mut ngx_http_handler_pt;
30+
if h.is_null() {
31+
return core::Status::NGX_ERROR.into();
32+
}
33+
// set an phase handler
34+
*h = Some(awssigv4_header_handler);
35+
core::Status::NGX_OK.into()
3136
}
32-
// set an phase handler
33-
*h = Some(awssigv4_header_handler);
34-
core::Status::NGX_OK.into()
3537
}
3638
}
3739

@@ -298,10 +300,13 @@ http_request_handler!(awssigv4_header_handler, |request: &mut Request| {
298300
for (name, value) in request.headers_in_iterator() {
299301
if let Ok(name) = name.to_str() {
300302
if name.to_lowercase() == "host" {
301-
if let Ok(value) = http::HeaderValue::from_bytes(value.as_bytes()) {
302-
headers.insert(http::header::HOST, value);
303-
} else {
304-
return core::Status::NGX_DECLINED;
303+
match http::HeaderValue::from_bytes(value.as_bytes()) {
304+
Ok(value) => {
305+
headers.insert(http::header::HOST, value);
306+
}
307+
_ => {
308+
return core::Status::NGX_DECLINED;
309+
}
305310
}
306311
}
307312
} else {

examples/curl.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,21 @@ impl http::HttpModule for Module {
1818
}
1919

2020
unsafe extern "C" fn postconfiguration(cf: *mut ngx_conf_t) -> ngx_int_t {
21-
// SAFETY: this function is called with non-NULL cf always
22-
let cf = &mut *cf;
23-
let cmcf = NgxHttpCoreModule::main_conf_mut(cf).expect("http core main conf");
24-
25-
let h = ngx_array_push(
26-
&mut cmcf.phases[ngx_http_phases_NGX_HTTP_ACCESS_PHASE as usize].handlers,
27-
) as *mut ngx_http_handler_pt;
28-
if h.is_null() {
29-
return core::Status::NGX_ERROR.into();
21+
unsafe {
22+
// SAFETY: this function is called with non-NULL cf always
23+
let cf = &mut *cf;
24+
let cmcf = NgxHttpCoreModule::main_conf_mut(cf).expect("http core main conf");
25+
26+
let h = ngx_array_push(
27+
&mut cmcf.phases[ngx_http_phases_NGX_HTTP_ACCESS_PHASE as usize].handlers,
28+
) as *mut ngx_http_handler_pt;
29+
if h.is_null() {
30+
return core::Status::NGX_ERROR.into();
31+
}
32+
// set an Access phase handler
33+
*h = Some(curl_access_handler);
34+
core::Status::NGX_OK.into()
3035
}
31-
// set an Access phase handler
32-
*h = Some(curl_access_handler);
33-
core::Status::NGX_OK.into()
3436
}
3537
}
3638

examples/shared_dict.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,18 @@ impl HttpModule for HttpSharedDictModule {
2323
}
2424

2525
unsafe extern "C" fn preconfiguration(cf: *mut ngx_conf_t) -> ngx_int_t {
26-
for mut v in NGX_HTTP_SHARED_DICT_VARS {
27-
let var = ngx_http_add_variable(cf, &mut v.name, v.flags);
28-
if var.is_null() {
29-
return Status::NGX_ERROR.into();
26+
unsafe {
27+
for mut v in NGX_HTTP_SHARED_DICT_VARS {
28+
let var = ngx_http_add_variable(cf, &mut v.name, v.flags);
29+
if var.is_null() {
30+
return Status::NGX_ERROR.into();
31+
}
32+
(*var).get_handler = v.get_handler;
33+
(*var).set_handler = v.set_handler;
34+
(*var).data = v.data;
3035
}
31-
(*var).get_handler = v.get_handler;
32-
(*var).set_handler = v.set_handler;
33-
(*var).data = v.data;
36+
Status::NGX_OK.into()
3437
}
35-
Status::NGX_OK.into()
3638
}
3739
}
3840

0 commit comments

Comments
 (0)