#611 Serving static files doesn't work as advertised
Reporter
Thijs Alkemade
Owner
Zash
Created
Updated
Stars
★ (1)
Tags
Status-Fixed
mod_http_files
Type-Defect
Priority-Medium
Milestone-0.9
Thijs Alkemade
on
I've followed the instructions on https://prosody.im/doc/developers/http#serving_files to serve static files from a module. However, it doesn't work, even with the example given on that page.
The first problem is that it throws an exception:
http.server error Traceback[httpserver]: ...ody/0.9/build/lib/prosody/modules/mod_http_files.lua:62: attempt to index local 'path' (a nil value)
stack traceback:
...ody/0.9/build/lib/prosody/modules/mod_http_files.lua:62: in function 'sanitize_path'
...ody/0.9/build/lib/prosody/modules/mod_http_files.lua:92: in function '?'
...ojects/Prosody/0.9/build/lib/prosody/util/events.lua:67: in function 'fire_event'
...ts/Prosody/0.9/build/lib/prosody/net/http/server.lua:221: in function <...ts/Prosody/0.9/build/lib/prosody/net/http/server.lua:164>
(tail call): ?
[C]: in function 'xpcall'
...ts/Prosody/0.9/build/lib/prosody/net/http/server.lua:108: in function 'process_next'
...ts/Prosody/0.9/build/lib/prosody/net/http/server.lua:124: in function 'success_cb'
...ts/Prosody/0.9/build/lib/prosody/net/http/parser.lua:154: in function 'feed'
...ts/Prosody/0.9/build/lib/prosody/net/http/server.lua:150: in function <...ts/Prosody/0.9/build/lib/prosody/net/http/server.lua:149>
(tail call): ?
.../Prosody/0.9/build/lib/prosody/net/server_select.lua:867: in function <.../Prosody/0.9/build/lib/prosody/net/server_select.lua:849>
[C]: in function 'xpcall'
./bin/prosody:376: in function 'loop'
./bin/prosody:407: in main chunk
[C]: ?
This seems to be due to serve_file receiving different arguments than it expects. I managed to fix this with https://code.xnyhps.nl/prosody/0.9/rev/92f892811d2b.
The second problem is that when the path isn't a wildcard, it resolves the full path rather strangely. With the example from the wiki, it tries to read the file:
/Users/thijs/Projects/Prosody/0.9/build/lib/prosody/modules/my_file.txt//mymodule/a_file.txt
This is not what I expect, I expected it to look for just:
/Users/thijs/Projects/Prosody/0.9/build/lib/prosody/modules/my_file.txt
Reading the rest of the code, the commit is probably wrong because it causes the second problem. I don't really understand how the directory listing code is supposed to work, so I can't propose a correct patch.
I've followed the instructions on https://prosody.im/doc/developers/http#serving_files to serve static files from a module. However, it doesn't work, even with the example given on that page. The first problem is that it throws an exception: http.server error Traceback[httpserver]: ...ody/0.9/build/lib/prosody/modules/mod_http_files.lua:62: attempt to index local 'path' (a nil value) stack traceback: ...ody/0.9/build/lib/prosody/modules/mod_http_files.lua:62: in function 'sanitize_path' ...ody/0.9/build/lib/prosody/modules/mod_http_files.lua:92: in function '?' ...ojects/Prosody/0.9/build/lib/prosody/util/events.lua:67: in function 'fire_event' ...ts/Prosody/0.9/build/lib/prosody/net/http/server.lua:221: in function <...ts/Prosody/0.9/build/lib/prosody/net/http/server.lua:164> (tail call): ? [C]: in function 'xpcall' ...ts/Prosody/0.9/build/lib/prosody/net/http/server.lua:108: in function 'process_next' ...ts/Prosody/0.9/build/lib/prosody/net/http/server.lua:124: in function 'success_cb' ...ts/Prosody/0.9/build/lib/prosody/net/http/parser.lua:154: in function 'feed' ...ts/Prosody/0.9/build/lib/prosody/net/http/server.lua:150: in function <...ts/Prosody/0.9/build/lib/prosody/net/http/server.lua:149> (tail call): ? .../Prosody/0.9/build/lib/prosody/net/server_select.lua:867: in function <.../Prosody/0.9/build/lib/prosody/net/server_select.lua:849> [C]: in function 'xpcall' ./bin/prosody:376: in function 'loop' ./bin/prosody:407: in main chunk [C]: ? This seems to be due to serve_file receiving different arguments than it expects. I managed to fix this with https://code.xnyhps.nl/prosody/0.9/rev/92f892811d2b. The second problem is that when the path isn't a wildcard, it resolves the full path rather strangely. With the example from the wiki, it tries to read the file: /Users/thijs/Projects/Prosody/0.9/build/lib/prosody/modules/my_file.txt//mymodule/a_file.txt This is not what I expect, I expected it to look for just: /Users/thijs/Projects/Prosody/0.9/build/lib/prosody/modules/my_file.txt
That second link should be: https://code.xnyhps.nl/prosody/0.9/rev/92f892811d2b
Reading the rest of the code, the commit is probably wrong because it causes the second problem. I don't really understand how the directory listing code is supposed to work, so I can't propose a correct patch.
This looks like a regression from #520.
ChangesThe code originally allowed for the path argument to be empty, it then used the entire configured path from the serve() call.
ChangesOT: Where did this empty tag come from?
ChangesFixed in http://hg.prosody.im/0.9/rev/b5b7ae2901e6 Testing appreciated
Changes