diff options
Diffstat (limited to '')
-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); |