summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--API-Rust.md33
-rw-r--r--src/rust/unit-wasm-sys/rusty.rs12
2 files changed, 45 insertions, 0 deletions
diff --git a/API-Rust.md b/API-Rust.md
index 8e2b6a9..8a98fe6 100644
--- a/API-Rust.md
+++ b/API-Rust.md
@@ -78,6 +78,8 @@ and there isn't a real need to create wrappers specifically for them.
* [uwr_http_send_response](#uwr_http_send_response)
* [uwr_http_init_headers](#uwr_http_init_headers)
* [uwr_http_add_header](#uwr_http_add_header)
+ * [uwr_http_add_header_content_type](#uwr_http_add_header_content_type)
+ * [uwr_http_add_header_content_len](#uwr_http_add_header_content_len)
* [uwr_http_send_headers](#uwr_http_send_headers)
* [uwr_http_response_end](#uwr_http_response_end)
* [uwr_mem_get_init_size](#uwr_mem_get_init_size)
@@ -859,6 +861,37 @@ uwr_http_add_header(
);
```
+### uwr_http_add_header_content_type
+
+```Rust
+pub fn uwr_http_add_header_content_type(ctx: *mut luw_ctx_t, ctype: &str);
+```
+
+A convenience function for setting the 'Content-Type' response header.
+E.g the above example that adds the _Content-Type_ header could be
+written as
+
+```Rust
+uwr_http_add_header_content_type(ctx, "text/plain");
+```
+
+### uwr_http_add_header_content_len
+
+```Rust
+pub fn uwr_http_add_header_content_len(ctx: *mut luw_ctx_t);
+```
+
+A convenience function for setting the 'Content-Length' response header.
+E.g the above example that adds the _Content-Length_ header could be
+written as
+
+```Rust
+uwr_http_add_header_content_len(ctx);
+```
+
+This function uses [uwr_get_response_data_size](#uwr_get_response_data_size)
+internally to get the size of the response data.
+
### uwr_http_send_headers
```Rust
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);