[njs] HTTP: removed response object deprecated in 0.2.2.

Dmitry Volyntsev xeioex at nginx.com
Mon Jan 28 13:20:41 UTC 2019


details:   https://hg.nginx.org/njs/rev/23df46c40a53
branches:  
changeset: 737:23df46c40a53
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Mon Jan 28 16:17:42 2019 +0300
description:
HTTP: removed response object deprecated in 0.2.2.

diffstat:

 nginx/ngx_http_js_module.c |  303 +--------------------------------------------
 1 files changed, 5 insertions(+), 298 deletions(-)

diffs (467 lines):

diff -r 72fce46a7669 -r 23df46c40a53 nginx/ngx_http_js_module.c
--- a/nginx/ngx_http_js_module.c	Wed Jan 23 19:48:19 2019 +0300
+++ b/nginx/ngx_http_js_module.c	Mon Jan 28 16:17:42 2019 +0300
@@ -15,7 +15,6 @@
 typedef struct {
     njs_vm_t            *vm;
     const njs_extern_t  *req_proto;
-    const njs_extern_t  *res_proto;
 } ngx_http_js_main_conf_t;
 
 
@@ -27,9 +26,9 @@ typedef struct {
 typedef struct {
     njs_vm_t            *vm;
     ngx_log_t           *log;
-    njs_opaque_value_t   args[2];
     ngx_uint_t           done;
     ngx_int_t            status;
+    njs_opaque_value_t   request;
     njs_opaque_value_t   request_body;
     ngx_str_t            redirect_uri;
 } ngx_http_js_ctx_t;
@@ -62,8 +61,6 @@ static void ngx_http_js_cleanup_vm(void 
 
 static njs_ret_t ngx_http_js_ext_get_string(njs_vm_t *vm, njs_value_t *value,
     void *obj, uintptr_t data);
-static njs_ret_t ngx_http_js_ext_set_string(njs_vm_t *vm, void *obj,
-    uintptr_t data, nxt_str_t *value);
 static njs_ret_t ngx_http_js_ext_foreach_header(njs_vm_t *vm, void *obj,
     void *next, uintptr_t data);
 static njs_ret_t ngx_http_js_ext_next_header(njs_vm_t *vm, njs_value_t *value,
@@ -80,10 +77,6 @@ static njs_ret_t ngx_http_js_ext_get_sta
     void *obj, uintptr_t data);
 static njs_ret_t ngx_http_js_ext_set_status(njs_vm_t *vm, void *obj,
     uintptr_t data, nxt_str_t *value);
-static njs_ret_t ngx_http_js_ext_get_content_length(njs_vm_t *vm,
-    njs_value_t *value, void *obj, uintptr_t data);
-static njs_ret_t ngx_http_js_ext_set_content_length(njs_vm_t *vm, void *obj,
-    uintptr_t data, nxt_str_t *value);
 static njs_ret_t ngx_http_js_ext_send_header(njs_vm_t *vm, njs_value_t *args,
     nxt_uint_t nargs, njs_index_t unused);
 static njs_ret_t ngx_http_js_ext_send(njs_vm_t *vm, njs_value_t *args,
@@ -110,10 +103,6 @@ static njs_ret_t ngx_http_js_ext_get_rem
     njs_value_t *value, void *obj, uintptr_t data);
 static njs_ret_t ngx_http_js_ext_get_request_body(njs_vm_t *vm,
     njs_value_t *value, void *obj, uintptr_t data);
-static njs_ret_t ngx_http_js_ext_get_headers(njs_vm_t *vm, njs_value_t *value,
-    void *obj, uintptr_t data);
-static njs_ret_t ngx_http_js_ext_foreach_headers(njs_vm_t *vm, void *obj,
-    void *next); /*FIXME*/
 static njs_ret_t ngx_http_js_ext_get_header_in(njs_vm_t *vm, njs_value_t *value,
     void *obj, uintptr_t data);
 static njs_ret_t ngx_http_js_ext_foreach_header_in(njs_vm_t *vm, void *obj,
@@ -126,8 +115,6 @@ static njs_ret_t ngx_http_js_ext_next_ar
     void *obj, void *next);
 static njs_ret_t ngx_http_js_ext_get_variable(njs_vm_t *vm, njs_value_t *value,
     void *obj, uintptr_t data);
-static njs_ret_t ngx_http_js_ext_get_response(njs_vm_t *vm, njs_value_t *value,
-    void *obj, uintptr_t data);
 static njs_ret_t ngx_http_js_ext_subrequest(njs_vm_t *vm, njs_value_t *args,
     nxt_uint_t nargs, njs_index_t unused);
 static ngx_int_t ngx_http_js_subrequest(ngx_http_request_t *r,
@@ -217,106 +204,6 @@ ngx_module_t  ngx_http_js_module = {
 };
 
 
-static njs_external_t  ngx_http_js_ext_response[] = {
-
-    { nxt_string("headers"),
-      NJS_EXTERN_OBJECT,
-      NULL,
-      0,
-      ngx_http_js_ext_get_header_out,
-      ngx_http_js_ext_set_header_out,
-      NULL,
-      ngx_http_js_ext_foreach_header_out,
-      ngx_http_js_ext_next_header,
-      NULL,
-      0 },
-
-    { nxt_string("status"),
-      NJS_EXTERN_PROPERTY,
-      NULL,
-      0,
-      ngx_http_js_ext_get_status,
-      ngx_http_js_ext_set_status,
-      NULL,
-      NULL,
-      NULL,
-      NULL,
-      offsetof(ngx_http_request_t, headers_out.status) },
-
-    { nxt_string("contentType"),
-      NJS_EXTERN_PROPERTY,
-      NULL,
-      0,
-      ngx_http_js_ext_get_string,
-      ngx_http_js_ext_set_string,
-      NULL,
-      NULL,
-      NULL,
-      NULL,
-      offsetof(ngx_http_request_t, headers_out.content_type) },
-
-    { nxt_string("contentLength"),
-      NJS_EXTERN_PROPERTY,
-      NULL,
-      0,
-      ngx_http_js_ext_get_content_length,
-      ngx_http_js_ext_set_content_length,
-      NULL,
-      NULL,
-      NULL,
-      NULL,
-      0 },
-
-    { nxt_string("sendHeader"),
-      NJS_EXTERN_METHOD,
-      NULL,
-      0,
-      NULL,
-      NULL,
-      NULL,
-      NULL,
-      NULL,
-      ngx_http_js_ext_send_header,
-      0 },
-
-    { nxt_string("send"),
-      NJS_EXTERN_METHOD,
-      NULL,
-      0,
-      NULL,
-      NULL,
-      NULL,
-      NULL,
-      NULL,
-      ngx_http_js_ext_send,
-      0 },
-
-    { nxt_string("finish"),
-      NJS_EXTERN_METHOD,
-      NULL,
-      0,
-      NULL,
-      NULL,
-      NULL,
-      NULL,
-      NULL,
-      ngx_http_js_ext_finish,
-      0 },
-
-    { nxt_string("return"),
-      NJS_EXTERN_METHOD,
-      NULL,
-      0,
-      NULL,
-      NULL,
-      NULL,
-      NULL,
-      NULL,
-      ngx_http_js_ext_return,
-      0 },
-};
-
-
 static njs_external_t  ngx_http_js_ext_request[] = {
 
     { nxt_string("uri"),
@@ -379,18 +266,6 @@ static njs_external_t  ngx_http_js_ext_r
       NULL,
       0 },
 
-    { nxt_string("body"),
-      NJS_EXTERN_PROPERTY,
-      NULL,
-      0,
-      ngx_http_js_ext_get_reply_body,
-      NULL,
-      NULL,
-      NULL,
-      NULL,
-      NULL,
-      0 },
-
     { nxt_string("requestBody"),
       NJS_EXTERN_PROPERTY,
       NULL,
@@ -415,18 +290,6 @@ static njs_external_t  ngx_http_js_ext_r
       NULL,
       0 },
 
-    { nxt_string("headers"),
-      NJS_EXTERN_OBJECT,
-      NULL,
-      0,
-      ngx_http_js_ext_get_headers,
-      NULL,
-      NULL,
-      ngx_http_js_ext_foreach_headers,
-      ngx_http_js_ext_next_header,
-      NULL,
-      0 },
-
     { nxt_string("headersIn"),
       NJS_EXTERN_OBJECT,
       NULL,
@@ -487,18 +350,6 @@ static njs_external_t  ngx_http_js_ext_r
       NULL,
       0 },
 
-    { nxt_string("response"),
-      NJS_EXTERN_PROPERTY,
-      NULL,
-      0,
-      ngx_http_js_ext_get_response,
-      NULL,
-      NULL,
-      NULL,
-      NULL,
-      NULL,
-      0 },
-
     { nxt_string("subrequest"),
       NJS_EXTERN_METHOD,
       NULL,
@@ -622,18 +473,6 @@ static njs_external_t  ngx_http_js_exter
       NULL,
       NULL,
       0 },
-
-    { nxt_string("response"),
-      NJS_EXTERN_OBJECT,
-      ngx_http_js_ext_response,
-      nxt_nitems(ngx_http_js_ext_response),
-      NULL,
-      NULL,
-      NULL,
-      NULL,
-      NULL,
-      NULL,
-      0 },
 };
 
 
@@ -707,7 +546,7 @@ ngx_http_js_content_event_handler(ngx_ht
 
     ctx->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
 
-    if (njs_vm_call(ctx->vm, func, njs_value_arg(ctx->args), 2) != NJS_OK) {
+    if (njs_vm_call(ctx->vm, func, njs_value_arg(&ctx->request), 1) != NJS_OK) {
         njs_vm_retval_to_ext_string(ctx->vm, &exception);
 
         ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
@@ -839,7 +678,7 @@ ngx_http_js_variable(ngx_http_request_t 
 
     pending = njs_vm_pending(ctx->vm);
 
-    if (njs_vm_call(ctx->vm, func, njs_value_arg(ctx->args), 2) != NJS_OK) {
+    if (njs_vm_call(ctx->vm, func, njs_value_arg(&ctx->request), 1) != NJS_OK) {
         njs_vm_retval_to_ext_string(ctx->vm, &exception);
 
         ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
@@ -922,18 +761,12 @@ ngx_http_js_init_vm(ngx_http_request_t *
         return NGX_ERROR;
     }
 
-    rc = njs_vm_external_create(ctx->vm, njs_value_arg(&ctx->args[0]),
+    rc = njs_vm_external_create(ctx->vm, njs_value_arg(&ctx->request),
                                 jmcf->req_proto, r);
     if (rc != NXT_OK) {
         return NGX_ERROR;
     }
 
-    rc = njs_vm_external_create(ctx->vm, njs_value_arg(&ctx->args[1]),
-                                jmcf->res_proto, r);
-    if (rc != NXT_OK) {
-        return NGX_ERROR;
-    }
-
     return NGX_OK;
 }
 
@@ -975,31 +808,6 @@ ngx_http_js_ext_get_string(njs_vm_t *vm,
 
 
 static njs_ret_t
-ngx_http_js_ext_set_string(njs_vm_t *vm, void *obj, uintptr_t data,
-    nxt_str_t *value)
-{
-    char *p = obj;
-
-    ngx_str_t           *field;
-    ngx_http_request_t  *r;
-
-    r = (ngx_http_request_t *) obj;
-
-    field = (ngx_str_t *) (p + data);
-    field->len = value->length;
-
-    field->data = ngx_pnalloc(r->pool, value->length);
-    if (field->data == NULL) {
-        return NJS_ERROR;
-    }
-
-    ngx_memcpy(field->data, value->start, value->length);
-
-    return NJS_OK;
-}
-
-
-static njs_ret_t
 ngx_http_js_ext_foreach_header(njs_vm_t *vm, void *obj, void *next,
     uintptr_t data)
 {
@@ -1217,40 +1025,6 @@ ngx_http_js_ext_set_status(njs_vm_t *vm,
 
 
 static njs_ret_t
-ngx_http_js_ext_get_content_length(njs_vm_t *vm, njs_value_t *value, void *obj,
-    uintptr_t data)
-{
-    ngx_http_request_t  *r;
-
-    r = (ngx_http_request_t *) obj;
-
-    njs_value_number_set(value, r->headers_out.content_length_n);
-
-    return NJS_OK;
-}
-
-
-static njs_ret_t
-ngx_http_js_ext_set_content_length(njs_vm_t *vm, void *obj, uintptr_t data,
-    nxt_str_t *value)
-{
-    ngx_int_t            n;
-    ngx_http_request_t  *r;
-
-    n = ngx_atoi(value->start, value->length);
-    if (n == NGX_ERROR) {
-        return NJS_ERROR;
-    }
-
-    r = (ngx_http_request_t *) obj;
-
-    r->headers_out.content_length_n = n;
-
-    return NJS_OK;
-}
-
-
-static njs_ret_t
 ngx_http_js_ext_send_header(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
     njs_index_t unused)
 {
@@ -1656,27 +1430,6 @@ done:
 
 
 static njs_ret_t
-ngx_http_js_ext_get_headers(njs_vm_t *vm, njs_value_t *value,
-    void *obj, uintptr_t data)
-{
-    ngx_http_js_ctx_t   *ctx;
-    ngx_http_request_t  *r;
-
-    r = (ngx_http_request_t *) obj;
-
-    ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
-
-    if (ctx->done) {
-        /* simulate Reply.headers behavior */
-
-        return ngx_http_js_ext_get_header_out(vm, value, obj, data);
-    }
-
-    return ngx_http_js_ext_get_header_in(vm, value, obj, data);
-}
-
-
-static njs_ret_t
 ngx_http_js_ext_get_header_in(njs_vm_t *vm, njs_value_t *value, void *obj,
     uintptr_t data)
 {
@@ -1698,26 +1451,6 @@ ngx_http_js_ext_get_header_in(njs_vm_t *
 
 
 static njs_ret_t
-ngx_http_js_ext_foreach_headers(njs_vm_t *vm, void *obj, void *next)
-{
-    ngx_http_js_ctx_t   *ctx;
-    ngx_http_request_t  *r;
-
-    r = (ngx_http_request_t *) obj;
-
-    ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
-
-    if (ctx->done) {
-        /* simulate Reply.headers behavior */
-
-        return ngx_http_js_ext_foreach_header_out(vm, obj, next);
-    }
-
-    return ngx_http_js_ext_foreach_header_in(vm, obj, next);
-}
-
-
-static njs_ret_t
 ngx_http_js_ext_foreach_header_in(njs_vm_t *vm, void *obj, void *next)
 {
     return ngx_http_js_ext_foreach_header(vm, obj, next,
@@ -1834,23 +1567,6 @@ ngx_http_js_ext_get_variable(njs_vm_t *v
 
 
 static njs_ret_t
-ngx_http_js_ext_get_response(njs_vm_t *vm, njs_value_t *value, void *obj,
-    uintptr_t data)
-{
-    ngx_http_js_ctx_t   *ctx;
-    ngx_http_request_t  *r;
-
-    r = (ngx_http_request_t *) obj;
-
-    ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
-
-    njs_value_assign(value, njs_value_arg(&ctx->args[1]));
-
-    return NJS_OK;
-}
-
-
-static njs_ret_t
 ngx_http_js_ext_subrequest(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
     njs_index_t unused)
 {
@@ -2189,7 +1905,7 @@ ngx_http_js_ext_get_parent(njs_vm_t *vm,
         return NJS_ERROR;
     }
 
-    njs_value_assign(value, njs_value_arg(&ctx->args[0]));
+    njs_value_assign(value, njs_value_arg(&ctx->request));
 
     return NJS_OK;
 }
@@ -2417,14 +2133,6 @@ ngx_http_js_include(ngx_conf_t *cf, ngx_
         return NGX_CONF_ERROR;
     }
 
-    jmcf->res_proto = njs_vm_external_prototype(jmcf->vm,
-                                                &ngx_http_js_externals[1]);
-    if (jmcf->res_proto == NULL) {
-        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
-                           "failed to add response proto");
-        return NGX_CONF_ERROR;
-    }
-
     rc = njs_vm_compile(jmcf->vm, &start, end);
 
     if (rc != NJS_OK) {
@@ -2520,7 +2228,6 @@ ngx_http_js_create_main_conf(ngx_conf_t 
      *
      *     conf->vm = NULL;
      *     conf->req_proto = NULL;
-     *     conf->res_proto = NULL;
      */
 
     return conf;


More information about the nginx-devel mailing list