Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

feature: added new constant ngx.HTTP_OPTIONS for the HTTP OPTIONS met…

…hod; also added support for OPTIONS method in the subrequest capture APIs. thanks Jónas Tryggvi Jóhannsson for requesting this in github issue #102.
  • Loading branch information...
commit 68638bd3a39690be02a8f68a0e0578ca43e3c0d5 1 parent 2b3f5f9
@agentzh agentzh authored
View
8 src/ngx_http_lua_consts.c
@@ -45,11 +45,15 @@ ngx_http_lua_inject_http_consts(lua_State *L)
lua_pushinteger(L, NGX_HTTP_PUT);
lua_setfield(L, -2, "HTTP_PUT");
+ lua_pushinteger(L, NGX_HTTP_HEAD);
+ lua_setfield(L, -2, "HTTP_HEAD");
+
lua_pushinteger(L, NGX_HTTP_DELETE);
lua_setfield(L, -2, "HTTP_DELETE");
- lua_pushinteger(L, NGX_HTTP_HEAD);
- lua_setfield(L, -2, "HTTP_HEAD");
+ lua_pushinteger(L, NGX_HTTP_OPTIONS);
+ lua_setfield(L, -2, "HTTP_OPTIONS");
+ /* }}} */
lua_pushinteger(L, NGX_HTTP_OK);
lua_setfield(L, -2, "HTTP_OK");
View
2  src/ngx_http_lua_headerfilterby.c
@@ -65,7 +65,7 @@ ngx_http_lua_header_filter_by_lua_env(lua_State *L, ngx_http_request_t *r)
#endif /* defined(NDK) && NDK */
/* {{{ initialize ngx.* namespace */
- lua_createtable(L, 0 /* narr */, 70 /* nrec */); /* ngx.* */
+ lua_createtable(L, 0 /* narr */, 71 /* nrec */); /* ngx.* */
ngx_http_lua_inject_internal_utils(r->connection->log, L);
View
2  src/ngx_http_lua_setby.c
@@ -195,7 +195,7 @@ ngx_http_lua_set_by_lua_env(lua_State *L, ngx_http_request_t *r, size_t nargs,
/* {{{ initialize ngx.* namespace */
- lua_createtable(L, 0 /* narr */, 70 /* nrec */); /* ngx.* */
+ lua_createtable(L, 0 /* narr */, 71 /* nrec */); /* ngx.* */
ngx_http_lua_inject_internal_utils(r->connection->log, L);
View
7 src/ngx_http_lua_subrequest.c
@@ -21,6 +21,8 @@ static ngx_str_t ngx_http_lua_post_method = ngx_http_lua_method_name("POST");
static ngx_str_t ngx_http_lua_head_method = ngx_http_lua_method_name("HEAD");
static ngx_str_t ngx_http_lua_delete_method =
ngx_http_lua_method_name("DELETE");
+static ngx_str_t ngx_http_lua_options_method =
+ ngx_http_lua_method_name("OPTIONS");
static ngx_str_t ngx_http_lua_content_length_header_key =
@@ -549,7 +551,6 @@ ngx_http_lua_adjust_subrequest(ngx_http_request_t *sr, ngx_uint_t method,
} else if (method != NGX_HTTP_PUT && method != NGX_HTTP_POST
&& r->headers_in.content_length_n > 0)
{
-
rc = ngx_http_lua_set_content_length_header(sr, 0);
if (rc != NGX_OK) {
return NGX_ERROR;
@@ -583,6 +584,10 @@ ngx_http_lua_adjust_subrequest(ngx_http_request_t *sr, ngx_uint_t method,
sr->method_name = ngx_http_lua_delete_method;
break;
+ case NGX_HTTP_OPTIONS:
+ sr->method_name = ngx_http_lua_options_method;
+ break;
+
default:
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"unsupported HTTP method: %u", (unsigned) method);
View
2  src/ngx_http_lua_util.c
@@ -498,7 +498,7 @@ init_ngx_lua_globals(ngx_conf_t *cf, lua_State *L)
ngx_http_lua_inject_ndk_api(L);
#endif /* defined(NDK) && NDK */
- lua_createtable(L, 0 /* narr */, 86 /* nrec */); /* ngx.* */
+ lua_createtable(L, 0 /* narr */, 87 /* nrec */); /* ngx.* */
ngx_http_lua_inject_internal_utils(cf->log, L);
View
52 t/020-subrequest.t
@@ -10,7 +10,7 @@ workers(1);
repeat_each(2);
-plan tests => repeat_each() * (blocks() * 2 + 6);
+plan tests => repeat_each() * (blocks() * 2 + 8);
$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
@@ -995,3 +995,53 @@ hello, world
--- error_log
subrequests cycle while processing "/t"
+
+
+=== TEST 38: OPTIONS
+--- config
+ location /other {
+ default_type 'foo/bar';
+ echo $echo_request_method;
+ }
+
+ location /lua {
+ content_by_lua '
+ res = ngx.location.capture("/other",
+ { method = ngx.HTTP_OPTIONS });
+
+ ngx.print(res.body)
+ ';
+ }
+--- request
+GET /lua
+--- response_body
+OPTIONS
+--- no_error_log
+[error]
+
+
+
+=== TEST 39: OPTIONS with a body
+--- config
+ location /other {
+ default_type 'foo/bar';
+ echo $echo_request_method;
+ echo_request_body;
+ }
+
+ location /lua {
+ content_by_lua '
+ res = ngx.location.capture("/other",
+ { method = ngx.HTTP_OPTIONS, body = "hello world" });
+
+ ngx.print(res.body)
+ ';
+ }
+--- request
+GET /lua
+--- response_body chop
+OPTIONS
+hello world
+--- no_error_log
+[error]
+
View
6 t/062-count.t
@@ -35,7 +35,7 @@ __DATA__
--- request
GET /test
--- response_body
-ngx: 86
+ngx: 87
--- no_error_log
[error]
@@ -56,7 +56,7 @@ ngx: 86
--- request
GET /test
--- response_body
-70
+71
--- no_error_log
[error]
@@ -84,7 +84,7 @@ GET /test
--- request
GET /test
--- response_body
-n = 70
+n = 71
--- no_error_log
[error]
Please sign in to comment.
Something went wrong with that request. Please try again.