@@ -76,6 +76,8 @@ and there isn't a real need to create wrappers specifically for them.
7676 * [ uwr_get_response_data_size] ( #uwr_get_response_data_size )
7777 * [ uwr_mem_write_buf] ( #uwr_mem_write_buf )
7878 * [ uwr_req_buf_append] ( #uwr_req_buf_append )
79+ * [ uwr_req_buf_copy] ( #uwr_req_buf_copy )
80+ * [ uwr_mem_splice_file] ( #uwr_mem_splice_file )
7981 * [ uwr_mem_fill_buf_from_req] ( #uwr_mem_fill_buf_from_req )
8082 * [ uwr_mem_reset] ( #uwr_mem_reset )
8183 * [ uwr_http_set_response_status] ( #uwr_http_set_response_status )
@@ -667,11 +669,12 @@ _Version: 0.2.0_
667669### uwr_get_http_content_len
668670
669671``` Rust
670- pub fn uwr_get_http_content_len (ctx : * const luw_ctx_t ) -> usize ;
672+ pub fn uwr_get_http_content_len (ctx : * const luw_ctx_t ) -> u64 ;
671673```
672674
673675This function returns the size of the overall content. I.e Content-Length.
674676
677+ Prior to version 0.3.0 it returned a usize
675678
676679### uwr_get_http_content_sent
677680
@@ -686,14 +689,14 @@ split over several calls to luw_request_handler().
686689### uwr_get_http_total_content_sent
687690
688691``` Rust
689- pub fn uwr_get_http_total_content_sent (ctx : * const luw_ctx_t ) -> usize ;
692+ pub fn uwr_get_http_total_content_sent (ctx : * const luw_ctx_t ) -> u64 ;
690693```
691694
692695This function returns the total length of the content that was sent to the
693696WebAssembly module so far. Remember, a single HTTP request may be split over
694697several calls to luw_request_handler().
695698
696- _ Version: 0.2.0_
699+ _ Version: 0.2.0_ Prior to 0.3.0 it returned a usize
697700
698701### uwr_http_is_tls
699702
@@ -836,6 +839,70 @@ pub extern "C" fn uwr_request_handler(addr: *mut u8) -> i32 {
836839}
837840```
838841
842+ ### uwr_req_buf_copy
843+
844+ ```Rust
845+ pub fn uwr_req_buf_copy(ctx: *mut luw_ctx_t, src: *const u8);
846+ ```
847+
848+ This function is analogous to [uwr_req_buf_append](#uwr_req_buf_append) but
849+ rather than appending the request data contained in _src_ to the previously
850+ setup *request_buffer* with uwr_set_req_buf(), it simply overwrites what's
851+ currently there.
852+
853+ This function could be used to handle large requests/uploads that you want to
854+ save out to disk or some such and can't buffer it all in memory.
855+
856+ ### uwr_mem_splice_file
857+
858+ ```Rust
859+ pub fn uwr_mem_splice_file(src: *const u8, f: &mut File) -> isize;
860+ ```
861+ This function write(2)'s the request data directly from the shared memory
862+ (_src_) to the file represented by the given _File_ object (_f_).
863+
864+ This can be used as an alternative to [uwr_req_buf_copy](#uwr_req_buf_copy)
865+ and avoids an extra copying of the request data.
866+
867+ Example
868+
869+ ```Rust
870+ pub extern "C" fn uwr_request_handler(addr: *mut u8) -> i32 {
871+ let ctx: *mut luw_ctx_t = unsafe { &mut CTX };
872+ let mut f;
873+ let bytes_wrote: isize;
874+ let mut total = unsafe { TOTAL_BYTES_WROTE };
875+
876+ if total == 0 {
877+ uwr_init_ctx(ctx, addr, 0);
878+ uwr_set_req_buf(ctx, unsafe { &mut REQUEST_BUF }, LUW_SRB_NONE);
879+
880+ f = File::create("/var/tmp/large-file.dat").unwrap();
881+ } else {
882+ f = File::options()
883+ .append(true)
884+ .open("/var/tmp/large-file.dat")
885+ .unwrap();
886+ }
887+
888+ bytes_wrote = uwr_mem_splice_file(addr, &mut f);
889+ if bytes_wrote == -1 {
890+ return -1;
891+ }
892+
893+ total += bytes_wrote as u64;
894+ if total == uwr_get_http_content_len(ctx) {
895+ total = 0;
896+
897+ uwr_http_response_end();
898+ }
899+
900+ unsafe { TOTAL_BYTES_WROTE = total };
901+
902+ return 0;
903+ }
904+ ```
905+
839906### uwr_mem_fill_buf_from_req
840907
841908```Rust
0 commit comments