diff options
author | Andrew Clayton <a.clayton@nginx.com> | 2024-09-05 21:27:00 +0100 |
---|---|---|
committer | Andrew Clayton <a.clayton@nginx.com> | 2024-09-06 01:35:43 +0100 |
commit | 8c83f5cc5aae007ffab5fc53e1e7db2298f6b7f6 (patch) | |
tree | d294994807f083ee5c3720b195a4eda7d4e89ca8 /c/wasi-http/0.2.0 | |
parent | c1c220bf0599166a41681dc3824c7be38631c0e0 (diff) | |
download | project_blackbird-8c83f5cc5aae007ffab5fc53e1e7db2298f6b7f6.tar.gz project_blackbird-8c83f5cc5aae007ffab5fc53e1e7db2298f6b7f6.tar.bz2 |
w-h/0.2.0/large-upload: Add some primitive error checking
Check the status of the open(2) call and return an appropriate HTTP
response code on error.
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
Diffstat (limited to 'c/wasi-http/0.2.0')
-rw-r--r-- | c/wasi-http/0.2.0/large-upload/component.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/c/wasi-http/0.2.0/large-upload/component.c b/c/wasi-http/0.2.0/large-upload/component.c index 1030b01..a4eeba6 100644 --- a/c/wasi-http/0.2.0/large-upload/component.c +++ b/c/wasi-http/0.2.0/large-upload/component.c @@ -14,6 +14,7 @@ #include <string.h> #include <fcntl.h> #include <unistd.h> +#include <errno.h> #include "proxy.h" @@ -51,6 +52,37 @@ void exports_wasi_http_incoming_handler_handle( fd = open("/var/tmp/wasm-wasi-component-upload.dat", O_CREAT|O_TRUNC|O_WRONLY, 0666); + if (fd == -1) { + wasi_http_types_status_code_t sc; + wasi_http_types_borrow_outgoing_response_t b_resp; + + printf("E: %s (/var/tmp/wasm-wasi-component-upload.dat)\n", + strerror(errno)); + + switch (errno) { + case EACCES: + case EFAULT: + case EPERM: + sc = 403; + break; + case EBADF: + case ENAMETOOLONG: + case ENODEV: + case ENOENT: + case ENOTDIR: + sc = 404; + break; + default: + sc = 500; + } + + b_resp = wasi_http_types_borrow_outgoing_response(resp); + wasi_http_types_method_outgoing_response_set_status_code(b_resp, + sc); + rerr.val.ok = resp; + + goto out_response; + } b_req = wasi_http_types_borrow_incoming_request(request); @@ -87,6 +119,7 @@ void exports_wasi_http_incoming_handler_handle( total_bytes_wrote += data.len; } while (total_bytes_wrote < content_len); +out_response: wasi_http_types_static_response_outparam_set(response_out, &rerr); close(fd); |