Skip to content

Commit 35916e7

Browse files
committed
qjs fetch.
1 parent 1d36e23 commit 35916e7

File tree

5 files changed

+3477
-1
lines changed

5 files changed

+3477
-1
lines changed

nginx/config

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ NJS_SRCS="$ngx_addon_dir/ngx_js.c \
1414
$ngx_addon_dir/ngx_js_shared_dict.c"
1515

1616
QJS_DEPS=""
17-
QJS_SRCS=""
17+
QJS_SRCS="$ngx_addon_dir/ngx_qjs_fetch.c"
1818

1919
NJS_OPENSSL_LIB=
2020
NJS_XSLT_LIB=

nginx/ngx_http_js_module.c

+1
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,7 @@ static JSClassDef ngx_http_qjs_headers_out_class = {
11331133
qjs_module_t *njs_http_qjs_addon_modules[] = {
11341134
&ngx_qjs_ngx_module,
11351135
&ngx_qjs_ngx_shared_dict_module,
1136+
&ngx_qjs_ngx_fetch_module,
11361137
/*
11371138
* Shared addons should be in the same order and the same positions
11381139
* in all nginx modules.

nginx/ngx_js.c

+25
Original file line numberDiff line numberDiff line change
@@ -1504,6 +1504,31 @@ ngx_qjs_string(JSContext *cx, JSValueConst val, ngx_str_t *dst)
15041504
}
15051505

15061506

1507+
int
1508+
ngx_qjs_array_length(JSContext *cx, uint32_t *plen, JSValueConst arr)
1509+
{
1510+
int ret;
1511+
JSValue value;
1512+
uint32_t len;
1513+
1514+
value = JS_GetPropertyStr(cx, arr, "length");
1515+
if (JS_IsException(value)) {
1516+
return -1;
1517+
}
1518+
1519+
ret = JS_ToUint32(cx, &len, value);
1520+
JS_FreeValue(cx, value);
1521+
1522+
if (ret) {
1523+
return -1;
1524+
}
1525+
1526+
*plen = len;
1527+
1528+
return 0;
1529+
}
1530+
1531+
15071532
static void
15081533
ngx_qjs_timer_handler(ngx_event_t *ev)
15091534
{

nginx/ngx_js.h

+8
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@
6363
#define NGX_QJS_CLASS_ID_SHARED (NGX_QJS_CLASS_ID_OFFSET + 11)
6464
#define NGX_QJS_CLASS_ID_SHARED_DICT (NGX_QJS_CLASS_ID_OFFSET + 12)
6565
#define NGX_QJS_CLASS_ID_SHARED_DICT_ERROR (NGX_QJS_CLASS_ID_OFFSET + 13)
66+
#define NGX_QJS_CLASS_ID_FETCH_HEADERS (NGX_QJS_CLASS_ID_OFFSET + 14)
67+
#define NGX_QJS_CLASS_ID_FETCH_REQUEST (NGX_QJS_CLASS_ID_OFFSET + 15)
68+
#define NGX_QJS_CLASS_ID_FETCH_RESPONSE (NGX_QJS_CLASS_ID_OFFSET + 16)
6669

6770

6871
typedef struct ngx_js_loc_conf_s ngx_js_loc_conf_t;
@@ -346,6 +349,10 @@ ngx_int_t ngx_qjs_exception(JSContext *cx, ngx_str_t *s);
346349
ngx_int_t ngx_qjs_integer(JSContext *cx, JSValueConst val, ngx_int_t *n);
347350
ngx_int_t ngx_qjs_string(JSContext *cx, JSValueConst val, ngx_str_t *str);
348351

352+
int ngx_qjs_array_length(JSContext *cx, uint32_t *plen, JSValueConst arr);
353+
JSValue ngx_qjs_ext_fetch(JSContext *cx, JSValueConst this_val, int argc,
354+
JSValueConst *argv);
355+
349356
#define ngx_qjs_prop(cx, type, start, len) \
350357
((type == NGX_JS_STRING) ? qjs_string_create(cx, start, len) \
351358
: qjs_buffer_create(cx, (u_char *) start, len))
@@ -381,6 +388,7 @@ extern qjs_module_t qjs_webcrypto_module;
381388
extern qjs_module_t qjs_zlib_module;
382389
extern qjs_module_t ngx_qjs_ngx_module;
383390
extern qjs_module_t ngx_qjs_ngx_shared_dict_module;
391+
extern qjs_module_t ngx_qjs_ngx_fetch_module;
384392

385393
#endif
386394

0 commit comments

Comments
 (0)