user vagrant;
worker_processes 1;
events {
worker_connections 1024;
}
http {
server {
listen 80;
default_type text/plain;
set $file1 /file1.txt;
set $file2 /file2.txt;
location /lua-dav/move {
content_by_lua_block {
ngx.req.set_header( "Destination", ngx.var.file2 )
local mv_res = ngx.location.capture(
ngx.var.file1, { method = ngx.HTTP_MOVE }
)
ngx.say(
"MOVE " .. ngx.var.file1 .. " -> " .. ngx.var.file2 ..
" response status: " .. mv_res.status
)
ngx.say( ngx.location.capture( "/" ).body )
}
}
location /lua-dav/delete {
content_by_lua_block {
for _,v in ipairs( { ngx.var.file1, ngx.var.file2 } ) do
local del_res = ngx.location.capture(
v, { method = ngx.HTTP_DELETE }
)
ngx.say( "DELETE " .. v .. " response status: " .. del_res.status )
ngx.say( ngx.location.capture( "/" ).body )
end
}
}
location / {
root /home/vagrant/dav_root;
dav_methods MOVE PUT DELETE;
create_full_put_path on;
autoindex on;
autoindex_format json;
}
}
}
vagrant@debian-7-9:~/dav_root$ ls -l
total 0
vagrant@debian-7-9:~/dav_root$ curl http://127.0.0.1/lua-dav/move
MOVE response status: 404
[
]
vagrant@debian-7-9:~/dav_root$ touch file1.txt
vagrant@debian-7-9:~/dav_root$ ls -l
total 0
-rw-r--r-- 1 vagrant vagrant 0 Oct 29 22:27 file1.txt
vagrant@debian-7-9:~/dav_root$ curl http://127.0.0.1/lua-dav/move
MOVE /file1.txt -> /file2.txt response status: 0
[
{ "name":"file2.txt", "type":"file", "mtime":"Thu, 29 Oct 2015 22:27:50 GMT", "size":0 }
]
vagrant@debian-7-9:~/dav_root$ ls -l
total 0
-rw-r--r-- 1 vagrant vagrant 0 Oct 29 22:27 file2.txt
vagrant@debian-7-9:~/dav_root$ curl http://127.0.0.1/lua-dav/delete
DELETE /file1.txt response status: 404
[
{ "name":"file2.txt", "type":"file", "mtime":"Thu, 29 Oct 2015 22:27:50 GMT", "size":0 }
]
DELETE /file2.txt response status: 0
[
]
vagrant@debian-7-9:~/dav_root$ ls -l
total 0
vagrant@debian-7-9:~/dav_root$
location /lua-dav/put {
content_by_lua_block {
local body_content = "blah blah blah"
local body_length = string.len( body_content )
ngx.req.set_header( "Content-type", "text/plain" )
ngx.req.set_header( "Content-length", body_length )
local put_res = ngx.location.capture(
ngx.var.file1, { method = ngx.HTTP_PUT, body = body_content }
)
ngx.say( "PUT response status: " .. put_res.status )
ngx.say( ngx.location.capture( "/" ).body )
}
}
But that reliably returned 500. Is that because the DAV module still can't read the request body as it's in a subrequest, as per https://github.com/openresty/lua-nginx-module/issues/375#issuecomment-46104177 ?
Anyway - hope it's not just me being dim!
Thanks again for openresty, it's amazing.
Cheers
Igor
You mean 1.9.3.2 RC1, right? RC2 is not out (yet) :)
Thanks for the bug report and test case! Just fixed in the git master
branch of ngx_lua:
https://github.com/openresty/lua-nginx-module/commit/4a9d4b11
It will get included in OpenResty 1.9.3.2 RC2 and ngx_lua 0.9.18 soon :)
--
You received this message because you are subscribed to the Google Groups "openresty-en" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openresty-en...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to a topic in the Google Groups "openresty-en" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openresty-en/4dW-3dNM_mM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to openresty-en...@googlegroups.com.
The ngx_dav module assumes that it reads the client request body
itself and it requires the body to be always put on the file system
during the read. So if we fake this in ngx.location.capture, then we
probably shouldn't use ngx_dav's PUT method in the first place (since
there's no gain here, really, as compared to writing to the file
directly ourselves, in Lua).