#611 Serving static files doesn't work as advertised

Reporter Thijs Alkemade
Owner Zash
Stars ★ (1)  
  • Milestone-0.9
  • Status-Fixed
  • Type-Defect
  • mod_http_files
  • Priority-Medium
  1. 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

  2. Thijs Alkemade on

    That second link should be: https://code.xnyhps.nl/prosody/0.9/rev/92f892811d2b

  3. Thijs Alkemade on

    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.

  4. Zash on

    This looks like a regression from #520.

    • tags
  5. Zash on

    The code originally allowed for the path argument to be empty, it then used the entire configured path from the serve() call.

    • tags
  6. Zash on

    OT: Where did this empty tag come from?

    • tags
  7. Zash on

    • tags mod_http_files
  8. Zash on

    • tags Status-Started
    • owner Zash
  9. Zash on

    Fixed in http://hg.prosody.im/0.9/rev/b5b7ae2901e6 Testing appreciated

    • tags Status-Fixed
  10. Zash on

    • tags Milestone-0.9

New comment