Skip to content

Commit b4c2ad1

Browse files
committed
feature: added ngx.HTTP_MKCOL, ngx.HTTP_COPY, ngx.HTTP_MOVE, and other WebDAV request method constants; also added corresponding support to ngx.req.set_method and ngx.location.capture. thanks Adallom Roy for the patch.
1 parent 601ddff commit b4c2ad1

8 files changed

+213
-6
lines changed

src/ngx_http_lua_consts.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,33 @@ ngx_http_lua_inject_http_consts(lua_State *L)
6060

6161
lua_pushinteger(L, NGX_HTTP_OPTIONS);
6262
lua_setfield(L, -2, "HTTP_OPTIONS");
63+
64+
lua_pushinteger(L, NGX_HTTP_MKCOL);
65+
lua_setfield(L, -2, "HTTP_MKCOL");
66+
67+
lua_pushinteger(L, NGX_HTTP_COPY);
68+
lua_setfield(L, -2, "HTTP_COPY");
69+
70+
lua_pushinteger(L, NGX_HTTP_MOVE);
71+
lua_setfield(L, -2, "HTTP_MOVE");
72+
73+
lua_pushinteger(L, NGX_HTTP_PROPFIND);
74+
lua_setfield(L, -2, "HTTP_PROPFIND");
75+
76+
lua_pushinteger(L, NGX_HTTP_PROPPATCH);
77+
lua_setfield(L, -2, "HTTP_PROPPATCH");
78+
79+
lua_pushinteger(L, NGX_HTTP_LOCK);
80+
lua_setfield(L, -2, "HTTP_LOCK");
81+
82+
lua_pushinteger(L, NGX_HTTP_UNLOCK);
83+
lua_setfield(L, -2, "HTTP_UNLOCK");
84+
85+
lua_pushinteger(L, NGX_HTTP_PATCH);
86+
lua_setfield(L, -2, "HTTP_PATCH");
87+
88+
lua_pushinteger(L, NGX_HTTP_TRACE);
89+
lua_setfield(L, -2, "HTTP_TRACE");
6390
/* }}} */
6491

6592
lua_pushinteger(L, NGX_HTTP_OK);

src/ngx_http_lua_req_method.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,42 @@ ngx_http_lua_ngx_req_set_method(lua_State *L)
109109
r->method_name = ngx_http_lua_options_method;
110110
break;
111111

112+
case NGX_HTTP_MKCOL:
113+
r->method_name = ngx_http_lua_mkcol_method;
114+
break;
115+
116+
case NGX_HTTP_COPY:
117+
r->method_name = ngx_http_lua_copy_method;
118+
break;
119+
120+
case NGX_HTTP_MOVE:
121+
r->method_name = ngx_http_lua_move_method;
122+
break;
123+
124+
case NGX_HTTP_PROPFIND:
125+
r->method_name = ngx_http_lua_propfind_method;
126+
break;
127+
128+
case NGX_HTTP_PROPPATCH:
129+
r->method_name = ngx_http_lua_proppatch_method;
130+
break;
131+
132+
case NGX_HTTP_LOCK:
133+
r->method_name = ngx_http_lua_lock_method;
134+
break;
135+
136+
case NGX_HTTP_UNLOCK:
137+
r->method_name = ngx_http_lua_unlock_method;
138+
break;
139+
140+
case NGX_HTTP_PATCH:
141+
r->method_name = ngx_http_lua_patch_method;
142+
break;
143+
144+
case NGX_HTTP_TRACE:
145+
r->method_name = ngx_http_lua_trace_method;
146+
break;
147+
112148
default:
113149
return luaL_error(L, "unsupported HTTP method: %d", method);
114150

src/ngx_http_lua_subrequest.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@ ngx_str_t ngx_http_lua_delete_method =
3434
ngx_http_lua_method_name("DELETE");
3535
ngx_str_t ngx_http_lua_options_method =
3636
ngx_http_lua_method_name("OPTIONS");
37+
ngx_str_t ngx_http_lua_copy_method = ngx_http_lua_method_name("COPY");
38+
ngx_str_t ngx_http_lua_move_method = ngx_http_lua_method_name("MOVE");
39+
ngx_str_t ngx_http_lua_lock_method = ngx_http_lua_method_name("LOCK");
40+
ngx_str_t ngx_http_lua_mkcol_method =
41+
ngx_http_lua_method_name("MKCOL");
42+
ngx_str_t ngx_http_lua_propfind_method =
43+
ngx_http_lua_method_name("PROPFIND");
44+
ngx_str_t ngx_http_lua_proppatch_method =
45+
ngx_http_lua_method_name("PROPPATCH");
46+
ngx_str_t ngx_http_lua_unlock_method =
47+
ngx_http_lua_method_name("UNLOCK");
48+
ngx_str_t ngx_http_lua_patch_method =
49+
ngx_http_lua_method_name("PATCH");
50+
ngx_str_t ngx_http_lua_trace_method =
51+
ngx_http_lua_method_name("TRACE");
3752

3853

3954
static ngx_str_t ngx_http_lua_content_length_header_key =
@@ -660,6 +675,42 @@ ngx_http_lua_adjust_subrequest(ngx_http_request_t *sr, ngx_uint_t method,
660675
sr->method_name = ngx_http_lua_options_method;
661676
break;
662677

678+
case NGX_HTTP_MKCOL:
679+
sr->method_name = ngx_http_lua_mkcol_method;
680+
break;
681+
682+
case NGX_HTTP_COPY:
683+
sr->method_name = ngx_http_lua_copy_method;
684+
break;
685+
686+
case NGX_HTTP_MOVE:
687+
sr->method_name = ngx_http_lua_move_method;
688+
break;
689+
690+
case NGX_HTTP_PROPFIND:
691+
sr->method_name = ngx_http_lua_propfind_method;
692+
break;
693+
694+
case NGX_HTTP_PROPPATCH:
695+
sr->method_name = ngx_http_lua_proppatch_method;
696+
break;
697+
698+
case NGX_HTTP_LOCK:
699+
sr->method_name = ngx_http_lua_lock_method;
700+
break;
701+
702+
case NGX_HTTP_UNLOCK:
703+
sr->method_name = ngx_http_lua_unlock_method;
704+
break;
705+
706+
case NGX_HTTP_PATCH:
707+
sr->method_name = ngx_http_lua_patch_method;
708+
break;
709+
710+
case NGX_HTTP_TRACE:
711+
sr->method_name = ngx_http_lua_trace_method;
712+
break;
713+
663714
default:
664715
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
665716
"unsupported HTTP method: %u", (unsigned) method);

src/ngx_http_lua_subrequest.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ extern ngx_str_t ngx_http_lua_post_method;
2323
extern ngx_str_t ngx_http_lua_head_method;
2424
extern ngx_str_t ngx_http_lua_delete_method;
2525
extern ngx_str_t ngx_http_lua_options_method;
26+
extern ngx_str_t ngx_http_lua_copy_method;
27+
extern ngx_str_t ngx_http_lua_move_method;
28+
extern ngx_str_t ngx_http_lua_lock_method;
29+
extern ngx_str_t ngx_http_lua_mkcol_method;
30+
extern ngx_str_t ngx_http_lua_propfind_method;
31+
extern ngx_str_t ngx_http_lua_proppatch_method;
32+
extern ngx_str_t ngx_http_lua_unlock_method;
33+
extern ngx_str_t ngx_http_lua_patch_method;
34+
extern ngx_str_t ngx_http_lua_trace_method;
2635

2736

2837
typedef struct ngx_http_lua_post_subrequest_data_s {

src/ngx_http_lua_util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ ngx_http_lua_inject_ngx_api(ngx_conf_t *cf, lua_State *L)
747747

748748
lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_lua_module);
749749

750-
lua_createtable(L, 0 /* narr */, 86 /* nrec */); /* ngx.* */
750+
lua_createtable(L, 0 /* narr */, 95 /* nrec */); /* ngx.* */
751751

752752
ngx_http_lua_inject_arg_api(L);
753753

t/020-subrequest.t

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2259,3 +2259,48 @@ truncated: true
22592259
--- no_error_log
22602260
[error]
22612261
2262+
2263+
2264+
=== TEST 61: WebDAV methods
2265+
--- config
2266+
location /other {
2267+
echo "method: $echo_request_method";
2268+
}
2269+
2270+
location /lua {
2271+
content_by_lua '
2272+
local methods = {
2273+
ngx.HTTP_MKCOL,
2274+
ngx.HTTP_COPY,
2275+
ngx.HTTP_MOVE,
2276+
ngx.HTTP_PROPFIND,
2277+
ngx.HTTP_PROPPATCH,
2278+
ngx.HTTP_LOCK,
2279+
ngx.HTTP_UNLOCK,
2280+
ngx.HTTP_PATCH,
2281+
ngx.HTTP_TRACE,
2282+
}
2283+
2284+
for i, method in ipairs(methods) do
2285+
res = ngx.location.capture("/other",
2286+
{ method = method })
2287+
ngx.print(res.body)
2288+
end
2289+
';
2290+
}
2291+
--- request
2292+
GET /lua
2293+
--- response_body
2294+
method: MKCOL
2295+
method: COPY
2296+
method: MOVE
2297+
method: PROPFIND
2298+
method: PROPPATCH
2299+
method: LOCK
2300+
method: UNLOCK
2301+
method: PATCH
2302+
method: TRACE
2303+
2304+
--- no_error_log
2305+
[error]
2306+

t/062-count.t

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ __DATA__
3535
--- request
3636
GET /test
3737
--- response_body
38-
ngx: 86
38+
ngx: 95
3939
--- no_error_log
4040
[error]
4141
@@ -56,7 +56,7 @@ ngx: 86
5656
--- request
5757
GET /test
5858
--- response_body
59-
86
59+
95
6060
--- no_error_log
6161
[error]
6262
@@ -84,7 +84,7 @@ GET /test
8484
--- request
8585
GET /test
8686
--- response_body
87-
n = 86
87+
n = 95
8888
--- no_error_log
8989
[error]
9090
@@ -301,7 +301,7 @@ GET /t
301301
--- response_body_like: 404 Not Found
302302
--- error_code: 404
303303
--- error_log
304-
ngx. entry count: 86
304+
ngx. entry count: 95
305305
306306
307307

t/088-req-method.t

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ repeat_each(2);
1313
plan tests => repeat_each() * (blocks() * 3);
1414

1515
#no_diff();
16-
#no_long_string();
16+
no_long_string();
1717
run_tests();
1818

1919
__DATA__
@@ -225,3 +225,42 @@ method: GET
225225
--- no_error_log
226226
[error]
227227

228+
229+
230+
=== TEST 11: set GET to WebDAV methods
231+
--- config
232+
location /t {
233+
content_by_lua '
234+
local methods = {
235+
ngx.HTTP_MKCOL,
236+
ngx.HTTP_COPY,
237+
ngx.HTTP_MOVE,
238+
ngx.HTTP_PROPFIND,
239+
ngx.HTTP_PROPPATCH,
240+
ngx.HTTP_LOCK,
241+
ngx.HTTP_UNLOCK,
242+
ngx.HTTP_PATCH,
243+
ngx.HTTP_TRACE,
244+
}
245+
246+
for i, method in ipairs(methods) do
247+
ngx.req.set_method(method)
248+
ngx.say("method: ", ngx.var.echo_request_method)
249+
end
250+
';
251+
}
252+
--- request
253+
HEAD /t
254+
--- response_body
255+
method: MKCOL
256+
method: COPY
257+
method: MOVE
258+
method: PROPFIND
259+
method: PROPPATCH
260+
method: LOCK
261+
method: UNLOCK
262+
method: PATCH
263+
method: TRACE
264+
--- no_error_log
265+
[error]
266+

0 commit comments

Comments
 (0)