r = njs_vm_external(vm, ngx_http_js_request_proto_id,
njs_argument(args, 0));
if (r == NULL) {
- njs_vm_error(vm, "\"this\" is not an external");
+ njs_vm_type_error(vm, "\"this\" is not an external");
return NJS_ERROR;
}
r = njs_vm_external(vm, ngx_http_js_request_proto_id,
njs_argument(args, 0));
if (r == NULL) {
- njs_vm_error(vm, "\"this\" is not an external");
+ njs_vm_type_error(vm, "\"this\" is not an external");
return NJS_ERROR;
}
ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
if (ctx->filter) {
- njs_vm_error(vm, "cannot send while in body filter");
+ njs_vm_type_error(vm, "cannot send while in body filter");
return NJS_ERROR;
}
r = njs_vm_external(vm, ngx_http_js_request_proto_id,
njs_argument(args, 0));
if (r == NULL) {
- njs_vm_error(vm, "\"this\" is not an external");
+ njs_vm_type_error(vm, "\"this\" is not an external");
return NJS_ERROR;
}
ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
if (!ctx->filter) {
- njs_vm_error(vm, "cannot send buffer while not filtering");
+ njs_vm_type_error(vm, "cannot send buffer while not filtering");
return NJS_ERROR;
}
if (ngx_js_string(vm, njs_arg(args, nargs, 1), &buffer) != NGX_OK) {
- njs_vm_error(vm, "failed to get buffer arg");
+ njs_vm_type_error(vm, "failed to get buffer arg");
return NJS_ERROR;
}
cl = ngx_chain_get_free_buf(r->pool, &ctx->free);
if (cl == NULL) {
- njs_vm_error(vm, "memory error");
+ njs_vm_memory_error(vm);
return NJS_ERROR;
}
r = njs_vm_external(vm, ngx_http_js_request_proto_id,
njs_argument(args, 0));
if (r == NULL) {
- njs_vm_error(vm, "\"this\" is not an external");
+ njs_vm_type_error(vm, "\"this\" is not an external");
return NJS_ERROR;
}
r = njs_vm_external(vm, ngx_http_js_request_proto_id,
njs_argument(args, 0));
if (r == NULL) {
- njs_vm_error(vm, "\"this\" is not an external");
+ njs_vm_type_error(vm, "\"this\" is not an external");
return NJS_ERROR;
}
ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
if (!ctx->filter) {
- njs_vm_error(vm, "cannot set done while not filtering");
+ njs_vm_type_error(vm, "cannot set done while not filtering");
return NJS_ERROR;
}
r = njs_vm_external(vm, ngx_http_js_request_proto_id,
njs_argument(args, 0));
if (r == NULL) {
- njs_vm_error(vm, "\"this\" is not an external");
+ njs_vm_type_error(vm, "\"this\" is not an external");
return NJS_ERROR;
}
r = njs_vm_external(vm, ngx_http_js_request_proto_id,
njs_argument(args, 0));
if (r == NULL) {
- njs_vm_error(vm, "\"this\" is not an external");
+ njs_vm_type_error(vm, "\"this\" is not an external");
return NJS_ERROR;
}
}
if (status < 0 || status > 999) {
- njs_vm_error(vm, "code is out of range");
+ njs_vm_range_error(vm, "code is out of range");
return NJS_ERROR;
}
|| !njs_value_is_null_or_undefined(njs_arg(args, nargs, 2)))
{
if (ngx_js_string(vm, njs_arg(args, nargs, 2), &text) != NGX_OK) {
- njs_vm_error(vm, "failed to convert text");
+ njs_vm_memory_error(vm);
return NJS_ERROR;
}
ctx->status = ngx_http_send_response(r, status, NULL, &cv);
if (ctx->status == NGX_ERROR) {
- njs_vm_error(vm, "failed to send response");
+ njs_vm_internal_error(vm, "failed to send response");
return NJS_ERROR;
}
r = njs_vm_external(vm, ngx_http_js_request_proto_id,
njs_argument(args, 0));
if (r == NULL) {
- njs_vm_error(vm, "\"this\" is not an external");
+ njs_vm_type_error(vm, "\"this\" is not an external");
return NJS_ERROR;
}
r = njs_vm_external(vm, ngx_http_js_request_proto_id,
njs_argument(args, 0));
if (r == NULL) {
- njs_vm_error(vm, "\"this\" is not an external");
+ njs_vm_type_error(vm, "\"this\" is not an external");
return NJS_ERROR;
}
if (r->parent != NULL) {
- njs_vm_error(vm, "internalRedirect cannot be called from a subrequest");
+ njs_vm_type_error(vm, "internalRedirect cannot be called from "
+ "a subrequest");
return NJS_ERROR;
}
ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
if (ctx->filter) {
- njs_vm_error(vm, "internalRedirect cannot be called while filtering");
+ njs_vm_type_error(vm, "internalRedirect cannot be called while "
+ "filtering");
return NJS_ERROR;
}
if (ngx_js_string(vm, njs_arg(args, nargs, 1), &uri) != NGX_OK) {
- njs_vm_error(vm, "failed to convert uri arg");
+ njs_vm_type_error(vm, "failed to convert uri arg");
return NJS_ERROR;
}
if (uri.length == 0) {
- njs_vm_error(vm, "uri is empty");
+ njs_vm_type_error(vm, "uri is empty");
return NJS_ERROR;
}
}
if (rc == NGX_JS_FORM_PARSE_ERROR) {
- njs_vm_error(vm, "%V", &error);
+ njs_vm_type_error(vm, "%V", &error);
return NJS_ERROR;
}
r = njs_vm_external(vm, ngx_http_js_request_proto_id,
njs_argument(args, 0));
if (r == NULL) {
- njs_vm_error(vm, "\"this\" is not an external");
+ njs_vm_type_error(vm, "\"this\" is not an external");
return NJS_ERROR;
}
}
if (ctx->body_read_event) {
- njs_vm_error(vm, "request body is already being read");
+ njs_vm_type_error(vm, "request body is already being read");
return NJS_ERROR;
}
resolve:
if (ngx_http_js_collect_body(r, ctx) != NGX_OK) {
- njs_vm_memory_error(vm);
+ njs_vm_internal_error(vm, "failed to read request body");
return NJS_ERROR;
}
r = njs_vm_external(vm, ngx_http_js_request_proto_id,
njs_argument(args, 0));
if (r == NULL) {
- njs_vm_error(vm, "\"this\" is not an external");
+ njs_vm_type_error(vm, "\"this\" is not an external");
return NJS_ERROR;
}
}
if (ctx->body_read_event) {
- njs_vm_error(vm, "request body is already being read");
+ njs_vm_type_error(vm, "request body is already being read");
return NJS_ERROR;
}
resolve:
if (ngx_http_js_collect_body(r, ctx) != NGX_OK) {
- njs_vm_memory_error(vm);
+ njs_vm_internal_error(vm, "failed to read request body");
return NJS_ERROR;
}
form = njs_vm_external(vm, ngx_http_js_request_form_proto_id,
njs_argument(args, 0));
if (form == NULL) {
- njs_vm_error(vm, "\"this\" is not a RequestForm");
+ njs_vm_type_error(vm, "\"this\" is not a RequestForm");
return NJS_ERROR;
}
form = njs_vm_external(vm, ngx_http_js_request_form_proto_id,
njs_argument(args, 0));
if (form == NULL) {
- njs_vm_error(vm, "\"this\" is not a RequestForm");
+ njs_vm_type_error(vm, "\"this\" is not a RequestForm");
return NJS_ERROR;
}
form = njs_vm_external(vm, ngx_http_js_request_form_proto_id, this);
if (form == NULL) {
- njs_vm_error(vm, "\"this\" is not a RequestForm");
+ njs_vm_type_error(vm, "\"this\" is not a RequestForm");
return NJS_ERROR;
}
callback = njs_arg(args, nargs, 1);
if (!njs_value_is_function(callback)) {
- njs_vm_error(vm, "\"callback\" is not a function");
+ njs_vm_type_error(vm, "\"callback\" is not a function");
return NJS_ERROR;
}
form = njs_vm_external(vm, ngx_http_js_request_form_proto_id,
njs_argument(args, 0));
if (form == NULL) {
- njs_vm_error(vm, "\"this\" is not a RequestForm");
+ njs_vm_type_error(vm, "\"this\" is not a RequestForm");
return NJS_ERROR;
}
r = njs_vm_external(vm, ngx_http_js_request_proto_id,
njs_argument(args, 0));
if (r == NULL) {
- njs_vm_error(vm, "\"this\" is not an external");
+ njs_vm_type_error(vm, "\"this\" is not an external");
return NJS_ERROR;
}
v = ngx_hash_find(&cmcf->variables_hash, key, name.data, val.length);
if (v == NULL) {
- njs_vm_error(vm, "variable not found");
+ njs_vm_type_error(vm, "variable not found");
return NJS_ERROR;
}
if (v->set_handler != NULL) {
vv = ngx_pcalloc(r->pool, sizeof(ngx_http_variable_value_t));
if (vv == NULL) {
- njs_vm_error(vm, "internal error");
+ njs_vm_memory_error(vm);
return NJS_ERROR;
}
}
if (!(v->flags & NGX_HTTP_VAR_INDEXED)) {
- njs_vm_error(vm, "variable is not writable");
+ njs_vm_type_error(vm, "variable is not writable");
return NJS_ERROR;
}
vv->data = ngx_pnalloc(r->pool, s.length);
if (vv->data == NULL) {
vv->valid = 0;
- njs_vm_error(vm, "internal error");
+ njs_vm_memory_error(vm);
return NJS_ERROR;
}
r = njs_vm_external(vm, ngx_http_js_request_proto_id,
njs_argument(args, 0));
if (r == NULL) {
- njs_vm_error(vm, "\"this\" is not an external");
+ njs_vm_type_error(vm, "\"this\" is not an external");
return NJS_ERROR;
}
ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
if (r->subrequest_in_memory) {
- njs_vm_error(vm, "subrequest can only be created for "
- "the primary request");
+ njs_vm_type_error(vm, "subrequest can only be created for "
+ "the primary request");
return NJS_ERROR;
}
if (ngx_js_string(vm, njs_arg(args, nargs, 1), &uri_arg) != NGX_OK) {
- njs_vm_error(vm, "failed to convert uri arg");
+ njs_vm_type_error(vm, "failed to convert uri arg");
return NJS_ERROR;
}
if (uri_arg.length == 0) {
- njs_vm_error(vm, "uri is empty");
+ njs_vm_type_error(vm, "uri is empty");
return NJS_ERROR;
}
if (njs_value_is_string(arg)) {
if (ngx_js_string(vm, arg, &args_arg) != NJS_OK) {
- njs_vm_error(vm, "failed to convert args");
+ njs_vm_type_error(vm, "failed to convert args");
return NJS_ERROR;
}
options = arg;
} else if (!njs_value_is_null_or_undefined(arg)) {
- njs_vm_error(vm, "failed to convert args");
+ njs_vm_type_error(vm, "failed to convert args");
return NJS_ERROR;
}
value = njs_vm_object_prop(vm, options, &args_key, &lvalue);
if (value != NULL) {
if (ngx_js_string(vm, value, &args_arg) != NGX_OK) {
- njs_vm_error(vm, "failed to convert options.args");
+ njs_vm_type_error(vm, "failed to convert options.args");
return NJS_ERROR;
}
}
value = njs_vm_object_prop(vm, options, &method_key, &lvalue);
if (value != NULL) {
if (ngx_js_string(vm, value, &method_name) != NGX_OK) {
- njs_vm_error(vm, "failed to convert options.method");
+ njs_vm_type_error(vm, "failed to convert options.method");
return NJS_ERROR;
}
value = njs_vm_object_prop(vm, options, &body_key, &lvalue);
if (value != NULL) {
if (ngx_js_string(vm, value, &body_arg) != NGX_OK) {
- njs_vm_error(vm, "failed to convert options.body");
+ njs_vm_type_error(vm, "failed to convert options.body");
return NJS_ERROR;
}
}
if (ngx_http_js_parse_unsafe_uri(r, &uri_arg, &args_arg) != NGX_OK) {
- njs_vm_error(vm, "unsafe uri");
+ njs_vm_type_error(vm, "unsafe uri");
return NJS_ERROR;
}
if (callback == NULL && !njs_value_is_undefined(arg)) {
if (!njs_value_is_function(arg)) {
- njs_vm_error(vm, "callback is not a function");
+ njs_vm_type_error(vm, "callback is not a function");
return NJS_ERROR;
} else {
}
if (detached && callback != NULL) {
- njs_vm_error(vm, "detached flag and callback are mutually exclusive");
+ njs_vm_type_error(vm, "detached flag and callback are mutually "
+ "exclusive");
return NJS_ERROR;
}
if (ngx_http_subrequest(r, &uri, rargs.len ? &rargs : NULL, &sr, ps, flags)
!= NGX_OK)
{
- njs_vm_error(vm, "subrequest creation failed");
+ njs_vm_internal_error(vm, "subrequest creation failed");
return NJS_ERROR;
}
memory_error:
- njs_vm_error(vm, "internal error");
+ njs_vm_memory_error(vm);
return NJS_ERROR;
}
n = ngx_atoi(h->value.data, h->value.len);
if (n == NGX_ERROR) {
h->hash = 0;
- njs_vm_error(vm, "failed converting argument "
- "to positive integer");
+ njs_vm_type_error(vm, "failed converting argument "
+ "to positive integer");
return NJS_ERROR;
}
req = JS_GetOpaque(this_val, NGX_QJS_CLASS_ID_HTTP_REQUEST);
if (req == NULL) {
- return JS_ThrowInternalError(cx, "\"this\" is not a request object");
+ return JS_ThrowTypeError(cx, "\"this\" is not a request object");
}
if (!JS_IsUndefined(req->args)) {
r = ngx_http_qjs_request(this_val);
if (r == NULL) {
- return JS_ThrowInternalError(cx, "\"this\" is not a request object");
+ return JS_ThrowTypeError(cx, "\"this\" is not a request object");
}
ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
r = ngx_http_qjs_request(this_val);
if (r == NULL) {
- return JS_ThrowInternalError(cx, "\"this\" is not a request object");
+ return JS_ThrowTypeError(cx, "\"this\" is not a request object");
}
if (ngx_http_send_special(r, NGX_HTTP_LAST) == NGX_ERROR) {
r = ngx_http_qjs_request(this_val);
if (r == NULL) {
- return JS_ThrowInternalError(cx, "\"this\" is not a request object");
+ return JS_ThrowTypeError(cx, "\"this\" is not a request object");
}
obj = JS_NewObjectProtoClass(cx, JS_NULL, NGX_QJS_CLASS_ID_HTTP_HEADERS_IN);
r = ngx_http_qjs_request(this_val);
if (r == NULL) {
- return JS_ThrowInternalError(cx, "\"this\" is not a request object");
+ return JS_ThrowTypeError(cx, "\"this\" is not a request object");
}
obj = JS_NewObjectProtoClass(cx, JS_NULL,
r = ngx_http_qjs_request(this_val);
if (r == NULL) {
- return JS_ThrowInternalError(cx, "\"this\" is not a request object");
+ return JS_ThrowTypeError(cx, "\"this\" is not a request object");
}
switch (r->http_version) {
r = ngx_http_qjs_request(this_val);
if (r == NULL) {
- return JS_ThrowInternalError(cx, "\"this\" is not a request object");
+ return JS_ThrowTypeError(cx, "\"this\" is not a request object");
}
return JS_NewBool(cx, r->internal);
r = ngx_http_qjs_request(this_val);
if (r == NULL) {
- return JS_ThrowInternalError(cx, "\"this\" is not a request object");
+ return JS_ThrowTypeError(cx, "\"this\" is not a request object");
}
if (r->parent != NULL) {
r = ngx_http_qjs_request(this_val);
if (r == NULL) {
- return JS_ThrowInternalError(cx, "\"this\" is not a request object");
+ return JS_ThrowTypeError(cx, "\"this\" is not a request object");
}
for (n = 0; n < argc; n++) {
req = JS_GetOpaque(this_val, NGX_QJS_CLASS_ID_HTTP_PERIODIC);
if (req == NULL) {
- return JS_ThrowInternalError(cx, "\"this\" is not a periodic object");
+ return JS_ThrowTypeError(cx, "\"this\" is not a periodic object");
}
obj = JS_NewObjectProtoClass(cx, JS_NULL, NGX_QJS_CLASS_ID_HTTP_VARS);
r = ngx_http_qjs_request(this_val);
if (r == NULL) {
- return JS_ThrowInternalError(cx, "\"this\" is not a request object");
+ return JS_ThrowTypeError(cx, "\"this\" is not a request object");
}
ctx = r->parent ? ngx_http_get_module_ctx(r->parent, ngx_http_js_module)
r = ngx_http_qjs_request(this_val);
if (r == NULL) {
- return JS_ThrowInternalError(cx, "\"this\" is not a request object");
+ return JS_ThrowTypeError(cx, "\"this\" is not a request object");
}
c = r->connection;
req = JS_GetOpaque(this_val, NGX_QJS_CLASS_ID_HTTP_REQUEST);
if (req == NULL) {
- return JS_ThrowInternalError(cx, "\"this\" is not a request object");
+ return JS_ThrowTypeError(cx, "\"this\" is not a request object");
}
buffer_type = ngx_js_buffer_type(type);
req = JS_GetOpaque(this_val, NGX_QJS_CLASS_ID_HTTP_REQUEST);
if (req == NULL) {
- return JS_ThrowInternalError(cx, "\"this\" is not a request object");
+ return JS_ThrowTypeError(cx, "\"this\" is not a request object");
}
buffer_type = ngx_js_buffer_type(type);
req = JS_GetOpaque(this_val, NGX_QJS_CLASS_ID_HTTP_REQUEST);
if (req == NULL) {
- return JS_ThrowInternalError(cx, "\"this\" is not a request object");
+ return JS_ThrowTypeError(cx, "\"this\" is not a request object");
}
r = req->request;
}
if (ctx->body_read_event) {
- return JS_ThrowInternalError(cx, "request body is already being read");
+ return JS_ThrowTypeError(cx, "request body is already being read");
}
event = ngx_pcalloc(r->pool, sizeof(ngx_qjs_event_t) + sizeof(JSValue) * 2);
resolve:
if (ngx_http_js_collect_body(r, ctx) != NGX_OK) {
- return JS_ThrowOutOfMemory(cx);
+ return JS_ThrowInternalError(cx, "failed to read request body");
}
return ngx_http_qjs_body_to_value(cx, ctx, (ngx_uint_t) magic);
}
if (rc == NGX_JS_FORM_PARSE_ERROR) {
- return JS_ThrowInternalError(cx, "%.*s", (int) error.len, error.data);
+ return JS_ThrowTypeError(cx, "%.*s", (int) error.len, error.data);
}
return JS_ThrowOutOfMemory(cx);
req = JS_GetOpaque(this_val, NGX_QJS_CLASS_ID_HTTP_REQUEST);
if (req == NULL) {
- return JS_ThrowInternalError(cx, "\"this\" is not a request object");
+ return JS_ThrowTypeError(cx, "\"this\" is not a request object");
}
if (ngx_http_qjs_request_form_max_keys(cx, argv[0], &max_keys) != NGX_OK) {
}
if (ctx->body_read_event) {
- return JS_ThrowInternalError(cx, "request body is already being read");
+ return JS_ThrowTypeError(cx, "request body is already being read");
}
event = ngx_pcalloc(r->pool, sizeof(ngx_qjs_event_t) + sizeof(JSValue) * 2);
resolve:
if (ngx_http_js_collect_body(r, ctx) != NGX_OK) {
- return JS_ThrowOutOfMemory(cx);
+ return JS_ThrowInternalError(cx, "failed to read request body");
}
return ngx_http_qjs_form_to_value(cx, r, ctx, max_keys);
form = JS_GetOpaque(this_val, NGX_QJS_CLASS_ID_HTTP_FORM);
if (form == NULL) {
- return JS_ThrowInternalError(cx, "\"this\" is not a RequestForm");
+ return JS_ThrowTypeError(cx, "\"this\" is not a RequestForm");
}
name = JS_ToCStringLen(cx, &name_len, argv[0]);
form = JS_GetOpaque(this_val, NGX_QJS_CLASS_ID_HTTP_FORM);
if (form == NULL) {
- return JS_ThrowInternalError(cx, "\"this\" is not a RequestForm");
+ return JS_ThrowTypeError(cx, "\"this\" is not a RequestForm");
}
name = JS_ToCStringLen(cx, &name_len, argv[0]);
form = JS_GetOpaque(this_val, NGX_QJS_CLASS_ID_HTTP_FORM);
if (form == NULL) {
- return JS_ThrowInternalError(cx, "\"this\" is not a RequestForm");
+ return JS_ThrowTypeError(cx, "\"this\" is not a RequestForm");
}
if (!JS_IsFunction(cx, argv[0])) {
form = JS_GetOpaque(this_val, NGX_QJS_CLASS_ID_HTTP_FORM);
if (form == NULL) {
- return JS_ThrowInternalError(cx, "\"this\" is not a RequestForm");
+ return JS_ThrowTypeError(cx, "\"this\" is not a RequestForm");
}
return JS_NewBool(cx, form->has_files);
r = ngx_http_qjs_request(this_val);
if (r == NULL) {
- return JS_ThrowInternalError(cx, "\"this\" is not a request object");
+ return JS_ThrowTypeError(cx, "\"this\" is not a request object");
}
if (ngx_qjs_integer(cx, argv[0], &status) != NGX_OK) {
ctx->status = ngx_http_send_response(r, status, NULL, &cv);
if (ctx->status == NGX_ERROR) {
- return JS_ThrowTypeError(cx, "failed to send response");
+ return JS_ThrowInternalError(cx, "failed to send response");
}
} else {
r = ngx_http_qjs_request(this_val);
if (r == NULL) {
- return JS_ThrowInternalError(cx, "\"this\" is not a request object");
+ return JS_ThrowTypeError(cx, "\"this\" is not a request object");
}
ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
r = ngx_http_qjs_request(this_val);
if (r == NULL) {
- return JS_ThrowInternalError(cx, "\"this\" is not a request object");
+ return JS_ThrowTypeError(cx, "\"this\" is not a request object");
}
return JS_NewInt32(cx, r->headers_out.status);
r = ngx_http_qjs_request(this_val);
if (r == NULL) {
- return JS_ThrowInternalError(cx, "\"this\" is not a request object");
+ return JS_ThrowTypeError(cx, "\"this\" is not a request object");
}
if (ngx_qjs_integer(cx, value, &n) != NGX_OK) {
r = ngx_http_qjs_request(this_val);
if (r == NULL) {
- return JS_ThrowInternalError(cx, "\"this\" is not a request object");
+ return JS_ThrowTypeError(cx, "\"this\" is not a request object");
}
field = (ngx_str_t *) ((u_char *) r + offset);
r = ngx_http_qjs_request(this_val);
if (r == NULL) {
- return JS_ThrowInternalError(cx, "\"this\" is not a request object");
+ return JS_ThrowTypeError(cx, "\"this\" is not a request object");
}
ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
b = ngx_calloc_buf(r->pool);
if (b == NULL) {
- return JS_ThrowInternalError(cx, "failed to allocate buffer");
+ return JS_ThrowOutOfMemory(cx);
}
b->start = s.data;
cl = ngx_alloc_chain_link(r->pool);
if (cl == NULL) {
- return JS_ThrowInternalError(cx, "failed to allocate chain link");
+ return JS_ThrowOutOfMemory(cx);
}
cl->buf = b;
r = ngx_http_qjs_request(this_val);
if (r == NULL) {
- return JS_ThrowInternalError(cx, "\"this\" is not a request object");
+ return JS_ThrowTypeError(cx, "\"this\" is not a request object");
}
ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
r = ngx_http_qjs_request(this_val);
if (r == NULL) {
- return JS_ThrowInternalError(cx, "\"this\" is not a request object");
+ return JS_ThrowTypeError(cx, "\"this\" is not a request object");
}
if (ngx_http_set_content_type(r) != NGX_OK) {
r = ngx_http_qjs_request(this_val);
if (r == NULL) {
- return JS_ThrowInternalError(cx, "\"this\" is not a request object");
+ return JS_ThrowTypeError(cx, "\"this\" is not a request object");
}
ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
r = ngx_http_qjs_request(this_val);
if (r == NULL) {
- return JS_ThrowInternalError(cx, "\"this\" is not a request object");
+ return JS_ThrowTypeError(cx, "\"this\" is not a request object");
}
ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
r = ngx_http_qjs_request(this_val);
if (r == NULL) {
- return JS_ThrowInternalError(cx, "\"this\" is not a request object");
+ return JS_ThrowTypeError(cx, "\"this\" is not a request object");
}
headers = (out) ? &r->headers_out.headers : &r->headers_in.headers;
r = ngx_http_qjs_request(this_val);
if (r == NULL) {
- return JS_ThrowInternalError(cx, "\"this\" is not a request object");
+ return JS_ThrowTypeError(cx, "\"this\" is not a request object");
}
obj = JS_NewObjectProtoClass(cx, JS_NULL, NGX_QJS_CLASS_ID_HTTP_VARS);
r = ngx_http_qjs_request(this_val);
if (r == NULL) {
- return JS_ThrowInternalError(cx, "\"this\" is not a request object");
+ return JS_ThrowTypeError(cx, "\"this\" is not a request object");
}
prefix = NULL;
r = (ngx_http_request_t *) ((uintptr_t) r & ~(uintptr_t) 1);
if (r == NULL) {
- (void) JS_ThrowInternalError(cx, "\"this\" is not a request object");
+ (void) JS_ThrowTypeError(cx, "\"this\" is not a request object");
return -1;
}
r = (ngx_http_request_t *) ((uintptr_t) r & ~(uintptr_t) 1);
if (r == NULL) {
- (void) JS_ThrowInternalError(cx, "\"this\" is not a request object");
+ (void) JS_ThrowTypeError(cx, "\"this\" is not a request object");
return -1;
}
JS_FreeCString(cx, (char *) name.data);
if (v == NULL) {
- (void) JS_ThrowInternalError(cx, "variable not found");
+ (void) JS_ThrowTypeError(cx, "variable not found");
return -1;
}
r = JS_GetOpaque(obj, NGX_QJS_CLASS_ID_HTTP_HEADERS_IN);
if (r == NULL) {
- (void) JS_ThrowInternalError(cx, "\"this\" is not a headers_in object");
+ (void) JS_ThrowTypeError(cx, "\"this\" is not a headers_in object");
return -1;
}
r = JS_GetOpaque(obj, NGX_QJS_CLASS_ID_HTTP_HEADERS_IN);
if (r == NULL) {
- (void) JS_ThrowInternalError(cx, "\"this\" is not a headers_in object");
+ (void) JS_ThrowTypeError(cx, "\"this\" is not a headers_in object");
return -1;
}
r = JS_GetOpaque(obj, NGX_QJS_CLASS_ID_HTTP_HEADERS_OUT);
if (r == NULL) {
- (void) JS_ThrowInternalError(cx, "\"this\" is not a headers_out"
- " object");
+ (void) JS_ThrowTypeError(cx, "\"this\" is not a headers_out object");
return -1;
}
n = ngx_atoi(h->value.data, h->value.len);
if (n == NGX_ERROR) {
h->hash = 0;
- (void) JS_ThrowInternalError(cx, "failed converting argument "
- "to positive integer");
+ (void) JS_ThrowTypeError(cx, "failed converting argument "
+ "to positive integer");
return -1;
}
r = JS_GetOpaque(obj, NGX_QJS_CLASS_ID_HTTP_HEADERS_OUT);
if (r == NULL) {
- (void) JS_ThrowInternalError(cx, "\"this\" is not a headers_out"
- " object");
+ (void) JS_ThrowTypeError(cx, "\"this\" is not a headers_out object");
return -1;
}
r = JS_GetOpaque(obj, NGX_QJS_CLASS_ID_HTTP_HEADERS_OUT);
if (r == NULL) {
- (void) JS_ThrowInternalError(cx, "\"this\" is not a headers_out"
- " object");
+ (void) JS_ThrowTypeError(cx, "\"this\" is not a headers_out object");
return -1;
}
r = JS_GetOpaque(obj, NGX_QJS_CLASS_ID_HTTP_HEADERS_OUT);
if (r == NULL) {
- (void) JS_ThrowInternalError(cx, "\"this\" is not a headers_out"
- " object");
+ (void) JS_ThrowTypeError(cx, "\"this\" is not a headers_out object");
return -1;
}
r.return(200, 'no_error');
} catch (e) {
- r.return(500, e.message);
+ r.return(500, `${e.constructor.name}:${e.message}`);
}
}
'fake multipart boundary does not restart header parsing');
like(http_post_form('/content_form_error', urlencoded_form('a=%')),
- qr/500.*malformed percent escape/s,
+ qr/500.*TypeError:malformed percent escape/s,
'urlencoded bare % at end is rejected');
like(http_post_form('/content_form_error', urlencoded_form('a=%4')),
- qr/500.*malformed percent escape/s,
+ qr/500.*TypeError:malformed percent escape/s,
'urlencoded %X with missing second digit is rejected');
like(http_post_form('/content_form_error', urlencoded_form('a=%gg')),
- qr/500.*malformed percent escape/s,
+ qr/500.*TypeError:malformed percent escape/s,
'urlencoded non-hex percent escape is rejected');
like(http_post_form('/content_form_error', urlencoded_form('%Z=1')),
- qr/500.*malformed percent escape/s,
+ qr/500.*TypeError:malformed percent escape/s,
'urlencoded malformed percent escape in name is rejected');
like(http_post_form('/content_form_error', ['text/plain', 'a=1']),
like(http_post_form('/content_form_error',
['application/x-www-form-urlencoded; =x', 'a=1']),
- qr/500.*malformed parameter/s,
+ qr/500.*TypeError:malformed parameter/s,
'malformed content type parameter is rejected');
like(http_post_form('/content_form_error', ['multipart/form-data', 'a=1']),
like(http_post_form('/content_form_error',
['multipart/form-data; boundary=""', '']),
- qr/500.*(invalid multipart boundary|empty parameter value)/s,
+ qr/500.*TypeError:(invalid multipart boundary|empty parameter value)/s,
'empty quoted multipart boundary is rejected');
like(http_post_form('/content_form_error',
["multipart/form-data; boundary=" . 'x' x 201, '']),
- qr/500.*invalid multipart boundary/s,
+ qr/500.*TypeError:invalid multipart boundary/s,
'multipart boundary over 200 bytes is rejected');
like(http_post_form('/content_form_error',
['multipart/form-data; boundary=X; boundary=Y', '--X--']),
- qr/500.*duplicate boundary parameter/s,
+ qr/500.*TypeError:duplicate boundary parameter/s,
'duplicate multipart boundary parameter is rejected');
like(http_post_form('/content_form_error',
['multipart/form-data; boundary=X junk', '--X--']),
- qr/500.*(malformed content type|malformed parameter)/s,
+ qr/500.*TypeError:(malformed content type|malformed parameter)/s,
'malformed trailing content type parameter data is rejected');
like(http_post_form('/content_form_error',
['multipart/form-data; boundary=XXX', '--XXXjunk']),
- qr/500.*malformed multipart boundary/s,
+ qr/500.*TypeError:malformed multipart boundary/s,
'multipart opening delimiter without CRLF is rejected');
like(http_post_form('/content_form_error',
['multipart/form-data; boundary=XXX', '-']),
- qr/500.*malformed multipart body/s,
+ qr/500.*TypeError:malformed multipart body/s,
'short multipart body without boundary marker is rejected');
like(http_post_form('/content_form_error',
['multipart/form-data; boundary=X',
'--X' . CRLF
. 'Content-Disposition: form-data; name="a"']),
- qr/500.*missing multipart header separator/s,
+ qr/500.*TypeError:missing multipart header separator/s,
'multipart part without header separator is rejected');
like(http_post_form('/content_form_error',
. 'X-Large: ' . ('a' x 17000) . CRLF . CRLF
. 'data' . CRLF
. '--X--']),
- qr/500.*multipart headers are too large/s,
+ qr/500.*TypeError:multipart headers are too large/s,
'multipart header block size limit is enforced');
like(http_post_form('/content_form_error',
. 'Content-Disposition: form-data; name="a"' . CRLF . CRLF
. 'data' . CRLF
. '--X--']),
- qr/500.*multipart header line is too long/s,
+ qr/500.*TypeError:multipart header line is too long/s,
'multipart header line size limit is enforced');
my $many_headers = join('', map { "X-$_: v" . CRLF } 1 .. 33);
. 'Content-Disposition: form-data; name="a"' . CRLF . CRLF
. 'data' . CRLF
. '--X--']),
- qr/500.*too many multipart headers/s,
+ qr/500.*TypeError:too many multipart headers/s,
'multipart header count limit is enforced');
like(http_post_form('/content_form_error',
. 'X-Other: foo' . CRLF . CRLF
. 'data' . CRLF
. '--X--']),
- qr/500.*missing Content-Disposition header/s,
+ qr/500.*TypeError:missing Content-Disposition header/s,
'multipart part without Content-Disposition is rejected');
like(http_post_form('/content_form_error',
. 'Content-Disposition: form-data; name="b"' . CRLF . CRLF
. 'data' . CRLF
. '--X--']),
- qr/500.*duplicate Content-Disposition header/s,
+ qr/500.*TypeError:duplicate Content-Disposition header/s,
'duplicate multipart Content-Disposition header is rejected');
like(http_post_form('/content_form_error',
. 'Content-Disposition: attachment; name="a"' . CRLF . CRLF
. 'data' . CRLF
. '--X--']),
- qr/500.*unsupported disposition type/s,
+ qr/500.*TypeError:unsupported disposition type/s,
'unsupported multipart disposition type is rejected');
like(http_post_form('/content_form_error',
. 'Content-Disposition: form-data' . CRLF . CRLF
. 'data' . CRLF
. '--X--']),
- qr/500.*multipart field name is required/s,
+ qr/500.*TypeError:multipart field name is required/s,
'multipart Content-Disposition without name is rejected');
like(http_post_form('/content_form_error',
. CRLF . CRLF
. 'data' . CRLF
. '--X--']),
- qr/500.*malformed Content-Disposition/s,
+ qr/500.*TypeError:malformed Content-Disposition/s,
'multipart Content-Disposition trailing data is rejected');
like(http_post_form('/content_form_error',
. CRLF . CRLF
. 'data' . CRLF
. '--X--']),
- qr/500.*duplicate name parameter/s,
+ qr/500.*TypeError:duplicate name parameter/s,
'duplicate multipart name parameter is rejected');
like(http_post_form('/content_form_error',
. 'filename="y"' . CRLF . CRLF
. 'data' . CRLF
. '--X--']),
- qr/500.*duplicate filename parameter/s,
+ qr/500.*TypeError:duplicate filename parameter/s,
'duplicate multipart filename parameter is rejected');
like(http_post_form('/content_form_error',
. 'Content-Disposition: form-data; name' . CRLF . CRLF
. 'data' . CRLF
. '--X--']),
- qr/500.*malformed parameter/s,
+ qr/500.*TypeError:malformed parameter/s,
'multipart parameter without equals is rejected');
like(http_post_form('/content_form_error',
. 'Content-Disposition: form-data; name=' . CRLF . CRLF
. 'data' . CRLF
. '--X--']),
- qr/500.*empty parameter value/s,
+ qr/500.*TypeError:empty parameter value/s,
'multipart parameter with empty unquoted value is rejected');
like(http_post_form('/content_form_error',
. CRLF . CRLF
. 'data' . CRLF
. '--X--']),
- qr/500.*unterminated quoted parameter/s,
+ qr/500.*TypeError:unterminated quoted parameter/s,
'multipart trailing backslash in quoted parameter is rejected');
like(http_post_form('/content_form_error',
. 'Content-Disposition: form-data; name="a"' . CRLF . CRLF
. 'data' . CRLF
. '--X--']),
- qr/500.*malformed multipart header/s,
+ qr/500.*TypeError:malformed multipart header/s,
'multipart header line without colon is rejected');
like(http_post_form('/content_form_error',
. 'Content-Disposition: form-data; name="a"' . CRLF . CRLF
. 'data' . CRLF
. '--Xjunk']),
- qr/500.*malformed multipart boundary/s,
+ qr/500.*TypeError:malformed multipart boundary/s,
'malformed multipart boundary after part is rejected');
like(http_post_form('/content_form_error',
['multipart/form-data; boundary=XXX', 'no boundary here at all']),
- qr/500.*malformed multipart body/s,
+ qr/500.*TypeError:malformed multipart body/s,
'multipart body without boundary marker is rejected');
like(http_post_form('/content_form_error',
'--X' . CRLF
. 'Content-Disposition: form-data; name="a"' . CRLF . CRLF
. 'value with no terminating boundary']),
- qr/500.*truncated multipart body/s,
+ qr/500.*TypeError:truncated multipart body/s,
'multipart body without closing boundary is rejected');
like(http_post_form('/content_form_limit', urlencoded_form('a=1&b=2')),
- qr/500.*maxKeys limit exceeded/s, 'maxKeys limit breach rejects');
+ qr/500.*TypeError:maxKeys limit exceeded/s, 'maxKeys limit breach rejects');
like(http_post_form('/content_form_limit', urlencoded_form('&a=1&&')),
qr/200.*no_error/s, 'urlencoded empty fields do not count for maxKeys');
like(http_post_form('/content_form_limit',
multipart_form({ name => 'a', value => '1' },
{ name => 'b', value => '2' })),
- qr/500.*maxKeys limit exceeded/s,
+ qr/500.*TypeError:maxKeys limit exceeded/s,
'multipart maxKeys limit breach rejects');
###############################################################################