| Age | Commit message (Collapse) | Author | Files | Lines |
|
libunit-wasm added two new functions, luw_req_buf_copy() &
luw_mem_splice_file(). See the previous two commits...
This second function takes a file-descriptor as one of its arguments, in
rusty we make this a Rust File object, then pass the underlying fd into
libunit-wasm.
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
|
|
Currently Wasm modules are limited to a 32bit address space (until at
least the memory64 work is completed). All the counters etc in the
request structure were u32's. Which matched with the 32bit memory
limitation.
However there is really no need to not allow >4GiB uploads that can be
saved off to disk or some such.
To do this we need to increase the ->content_len & ->total_content_sent
members to u64's and also adjust the return types of
(luw,uwr}_get_http_content_len() and
{luw,uwr}_get_http_total_content_sent() similarly.
However because we need the request structure to have the exact same
layout on 32bit (for Wasm modules) as it does on 64bit we need to re-jig
the order of some of these members and add a four-byte padding member.
Thus the request structure now looks like on 32bit (as shown by
pahole(1))
struct luw_req {
u32 method_off; /* 0 4 */
u32 method_len; /* 4 4 */
u32 version_off; /* 8 4 */
u32 version_len; /* 12 4 */
u32 path_off; /* 16 4 */
u32 path_len; /* 20 4 */
u32 query_off; /* 24 4 */
u32 query_len; /* 28 4 */
u32 remote_off; /* 32 4 */
u32 remote_len; /* 36 4 */
u32 local_addr_off; /* 40 4 */
u32 local_addr_len; /* 44 4 */
u32 local_port_off; /* 48 4 */
u32 local_port_len; /* 52 4 */
u32 server_name_off; /* 56 4 */
u32 server_name_len; /* 60 4 */
/* --- cacheline 1 boundary (64 bytes) --- */
u64 content_len; /* 64 8 */
u64 total_content_sent; /* 72 8 */
u32 content_sent; /* 80 4 */
u32 content_off; /* 84 4 */
u32 request_size; /* 88 4 */
u32 nr_fields; /* 92 4 */
u32 tls; /* 96 4 */
char __pad[4]; /* 100 4 */
struct luw_hdr_field fields[]; /* 104 0 */
/* size: 104, cachelines: 2, members: 25 */
/* last cacheline: 40 bytes */
};
and the same structure (taken from Unit) compiled as 64bit
struct nxt_wasm_request_s {
uint32_t method_off; /* 0 4 */
uint32_t method_len; /* 4 4 */
uint32_t version_off; /* 8 4 */
uint32_t version_len; /* 12 4 */
uint32_t path_off; /* 16 4 */
uint32_t path_len; /* 20 4 */
uint32_t query_off; /* 24 4 */
uint32_t query_len; /* 28 4 */
uint32_t remote_off; /* 32 4 */
uint32_t remote_len; /* 36 4 */
uint32_t local_addr_off; /* 40 4 */
uint32_t local_addr_len; /* 44 4 */
uint32_t local_port_off; /* 48 4 */
uint32_t local_port_len; /* 52 4 */
uint32_t server_name_off; /* 56 4 */
uint32_t server_name_len; /* 60 4 */
/* --- cacheline 1 boundary (64 bytes) --- */
uint64_t content_len; /* 64 8 */
uint64_t total_content_sent; /* 72 8 */
uint32_t content_sent; /* 80 4 */
uint32_t content_off; /* 84 4 */
uint32_t request_size; /* 88 4 */
uint32_t nfields; /* 92 4 */
uint32_t tls; /* 96 4 */
char __pad[4]; /* 100 4 */
nxt_wasm_http_field_t fields[]; /* 104 0 */
/* size: 104, cachelines: 2, members: 25 */
/* last cacheline: 40 bytes */
};
We can see the structures have the same layout, same size and no
padding.
We need the __pad member as otherwise I saw gcc and clang on Alpine
Linux automatically add the 'packed' attribute to the structure which
made the two structures not match.
Link: <https://github.com/WebAssembly/memory64>
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
|
|
The new uwr_http_set_response_status() function allows to set the HTTP
response status in Rust WebAssembly modules. It takes one of the
luw_http_status_t response status values.
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
|
|
When the uwr_get_http_content_str() function, which returns the request
body content as a string, was added it used uwr_get_http_content_len()
to determine the length of the returned string (the request body content
is not null-terminated).
This could potentially in some circumstances return too much data if the
request was split over multiple calls into the Wasm module and
uwr_get_http_content_str() was called before all the data had actually
been received.
Instead use the newly introduced uwr_get_http_total_content_sent()
function to determine the amount of data to return in the string as it
currently stands.
Fixes: bf968c9 ("Rust/rusty: Add uwr_get_http_content_str()")
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
|
|
This returns the total amount of content that the Wasm module has
received so far.
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
|
|
This may not matter in rust (if you use a function before the compiler
has seen a definition for it), but anyway in preparation for adding a
uwr_get_http_total_content_sent() function, put the content length
related functions before the functions that return the content.
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
|
|
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>
|
|
This function is like uwr_get_http_content() except that it returns a
Rust str.
This is more convenient if you want to operate on the body content
within Rust.
It's worth noting that uwr_get_http_content() returns a non null
terminated buffer which makes it tricky to work with in Rust.
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
|
|
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
|
|
The various uwr_get_ functions should take the context pointer as a
const.
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
|
|
Technically the context pointer can be passed in const even though we
then un-const it passing it to the luw_foreach_http_hdr() macro.
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
|
|
This was used to specify the index of the response header being added,
starting at 0 and incrementing by one for each header.
Instead of having the programmer specify this, track it internally.
We add an extra check in luw_http_add_header() to make sure we aren't
trying to add more headers than we said with luw_http_init_headers(), if
we are, simply return.
This updates the API-C.md and the various examples and 'rusty' API
wrapper.
Suggested-by: Liam Crilly <liam@nginx.com>
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
|
|
This adds a nice wrapper (aka rusty) around the generated libunit-wasm
bindings.
This should provide a more native rust like experience with the
following benefits
- No casting. So no things like 'as *mut c_void'
- Native rust strings. So no things like '.as_ptr() as *const c_char'
- Better ctx initialisation. Filed initialisation is now hidden away
- Great reduction in the amount of unsafe {} blocks required
- Generally more compact
There are also some new macros
- C2S!() converts a CStr to a Str
- S2C!() converts a formatted Str to a Cstr using format!()
- uwr_write_str!() a wrapper around luw_mem_writep_data and format!()
This wrapper uses a uwr (Unit Wasm Rust) prefix under a 'rusty'
namespace.
The luw_http_hdr_iter() function proved tricky to wrap and the callback
function still takes C style arguments due to the fact that this
function is called from the libunit-wasm C library.
The provided wrapper simply means we can use this without having to use
an unsafe {} block around it in application code.
Similarly with other functions that technically didn't need to be
wrapped, wrapping them means that the unsafe {} blocks are hidden away.
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
|