Skip to content

Commit

Permalink
Use bytes for request and response body
Browse files Browse the repository at this point in the history
  • Loading branch information
quangIO committed Jan 14, 2024
1 parent 7935802 commit b27acdb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "modsecurity-rs"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
authors = ["Quang Luong <[email protected]>"]
description = "Safe wrapper around libmodsecurity"
Expand All @@ -21,5 +21,4 @@ libc = "0.2.152"

[build-dependencies]
autocxx-build = "0.26"
cc = "1.0.83"
miette = { version = "5.10", features = ["fancy"] }
12 changes: 4 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,26 +138,22 @@ impl<'m, 'r> Transaction<'m, 'r> {
Ok(())
}

pub fn add_request_body(&mut self, body: &str) -> anyhow::Result<()> {
let len = body.len();
let body = CString::new(body)?;
pub fn add_request_body(&mut self, body: &[u8]) -> anyhow::Result<()> {
// # Safety: libmodsecurity must not reassign inner pointer
unsafe {
self.inner
.as_mut()
.appendRequestBody(body.as_ptr() as _, len);
.appendRequestBody(body.as_ptr(), body.len());
}
Ok(())
}

pub fn add_response_body(&mut self, body: &str) -> anyhow::Result<()> {
let len = body.len();
let body = CString::new(body)?;
pub fn add_response_body(&mut self, body: &[u8]) -> anyhow::Result<()> {
// # Safety: libmodsecurity must not reassign inner pointer
unsafe {
self.inner
.as_mut()
.appendResponseBody(body.as_ptr() as _, len);
.appendResponseBody(body.as_ptr(), body.len());
}
Ok(())
}
Expand Down
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

0 comments on commit b27acdb

Please sign in to comment.