aboutsummaryrefslogtreecommitdiff
path: root/nginx/ngx_js.c
diff options
context:
space:
mode:
authorDmitry Volyntsev <xeioex@nginx.com>2021-01-21 18:44:58 +0000
committerDmitry Volyntsev <xeioex@nginx.com>2021-01-21 18:44:58 +0000
commit73c75e41cf56c3b5ac6c0fd09293f20b838c2d5f (patch)
treebfe5b60d9f6dc0c40b63f1ecf12af8c5c2bd59da /nginx/ngx_js.c
parent300c8514379c4c2f062e5f3a09fe1ae553329165 (diff)
downloadnjs-73c75e41cf56c3b5ac6c0fd09293f20b838c2d5f.tar.gz
njs-73c75e41cf56c3b5ac6c0fd09293f20b838c2d5f.zip
Modules: added ngx.fetch().
This is an initial implementation of Fetch API. The following init options are supported: body, headers, buffer_size (nginx specific), max_response_body_size (nginx specific), method. The following properties and methods of Response object are implemented: arrayBuffer(), bodyUsed, json(), headers, ok, redirect, status, statusText, text(), type, url. The following properties and methods of Header object are implemented: get(), getAll(), has(). Notable limitations: only http:// scheme is supported, redirects are not handled. In collaboration with 洪志道 (Hong Zhi Dao).
Diffstat (limited to 'nginx/ngx_js.c')
-rw-r--r--nginx/ngx_js.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/nginx/ngx_js.c b/nginx/ngx_js.c
index f47b916f..e2c083a9 100644
--- a/nginx/ngx_js.c
+++ b/nginx/ngx_js.c
@@ -9,6 +9,7 @@
#include <ngx_config.h>
#include <ngx_core.h>
#include "ngx_js.h"
+#include "ngx_js_fetch.h"
static njs_external_t ngx_js_ext_core[] = {
@@ -50,6 +51,17 @@ static njs_external_t ngx_js_ext_core[] = {
.magic32 = NGX_LOG_ERR,
}
},
+
+ {
+ .flags = NJS_EXTERN_METHOD,
+ .name.string = njs_str("fetch"),
+ .writable = 1,
+ .configurable = 1,
+ .enumerable = 1,
+ .u.method = {
+ .native = ngx_js_ext_fetch,
+ }
+ },
};
@@ -117,10 +129,16 @@ ngx_js_string(njs_vm_t *vm, njs_value_t *value, njs_str_t *str)
ngx_int_t
ngx_js_core_init(njs_vm_t *vm, ngx_log_t *log)
{
+ ngx_int_t rc;
njs_int_t ret, proto_id;
njs_str_t name;
njs_opaque_value_t value;
+ rc = ngx_js_fetch_init(vm, log);
+ if (rc != NGX_OK) {
+ return NGX_ERROR;
+ }
+
proto_id = njs_vm_external_prototype(vm, ngx_js_ext_core,
njs_nitems(ngx_js_ext_core));
if (proto_id < 0) {
@@ -178,6 +196,16 @@ ngx_js_ext_constant(njs_vm_t *vm, njs_object_prop_t *prop,
njs_int_t
+ngx_js_ext_boolean(njs_vm_t *vm, njs_object_prop_t *prop,
+ njs_value_t *value, njs_value_t *setval, njs_value_t *retval)
+{
+ njs_value_boolean_set(retval, njs_vm_prop_magic32(prop));
+
+ return NJS_OK;
+}
+
+
+njs_int_t
ngx_js_ext_log(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
njs_index_t level)
{