summaryrefslogtreecommitdiffhomepage
path: root/src/rust/unit-wasm-sys/rusty.rs
diff options
context:
space:
mode:
authorAndrew Clayton <a.clayton@nginx.com>2023-08-29 15:53:58 +0100
committerAndrew Clayton <a.clayton@nginx.com>2023-08-29 17:36:43 +0100
commit15b73feec504db5f5381fbfedd7dc15cd8f8c7c9 (patch)
tree1a88ad94d92460b7fcf71ab3257aed9b38d0bf40 /src/rust/unit-wasm-sys/rusty.rs
parentbf968c99ce109c63fded62ec573c4bc247dc9c0a (diff)
downloadunit-wasm-15b73feec504db5f5381fbfedd7dc15cd8f8c7c9.tar.gz
unit-wasm-15b73feec504db5f5381fbfedd7dc15cd8f8c7c9.tar.bz2
Rust/rusty: Add a couple of convenience functions
This adds the following convenience functions for adding HTTP response headers, Content-Type & Content-length uwr_http_add_header_content_type(ctx: *mut luw_ctx_t, ctype: &str); uwr_http_add_header_content_len(ctx: *mut luw_ctx_t); These are perhaps the two most common headers so it makes sense to reduce the effort to adding them. E.g before uwr_http_add_header(&ctx, "Content-Type", "text/plain"); uwr_http_add_header( ctx, "Content-Length", &format!("{}", uwr_get_response_data_size(ctx)), ); after uwr_http_add_header_content_type(ctx, "text/plain"); uwr_http_add_header_content_len(ctx); Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
Diffstat (limited to 'src/rust/unit-wasm-sys/rusty.rs')
-rw-r--r--src/rust/unit-wasm-sys/rusty.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/rust/unit-wasm-sys/rusty.rs b/src/rust/unit-wasm-sys/rusty.rs
index 3bff4df..5135f56 100644
--- a/src/rust/unit-wasm-sys/rusty.rs
+++ b/src/rust/unit-wasm-sys/rusty.rs
@@ -197,6 +197,18 @@ pub fn uwr_http_add_header(ctx: *mut luw_ctx_t, name: &str, value: &str) {
}
}
+pub fn uwr_http_add_header_content_type(ctx: *mut luw_ctx_t, ctype: &str) {
+ uwr_http_add_header(ctx, "Content-Type", ctype);
+}
+
+pub fn uwr_http_add_header_content_len(ctx: *mut luw_ctx_t) {
+ uwr_http_add_header(
+ ctx,
+ "Content-Length",
+ &format!("{}", uwr_get_response_data_size(ctx)),
+ );
+}
+
pub fn uwr_http_send_headers(ctx: *const luw_ctx_t) {
unsafe {
luw_http_send_headers(ctx);