Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for directory listings in Staticmod #248

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

shym
Copy link

@shym shym commented Nov 29, 2024

The goal of this PR is to implement the "FIXME: staticmod dirs not implemented". The implementation might be too naïve to be included, at least as is. In particular:

  • the generation must load the full directory (so that the entries can be sorted),
  • consequently the generation should probably not be enabled when there are huge directories (which are usually a bad idea anyhow),
  • the listings are unstyled.

The idea was to make it so that

let () =
  let dir = Sys.getcwd () in
  Ocsigen_server.start
    ~ports:[ (`All, 8080) ]
    ~command_pipe:"/tmp/ocsigenserver-cmd" ~datadir:"/tmp" ~logdir:"/tmp" ~debugmode:true
    [
      Ocsigen_server.host
        [ Extendconfiguration.listdirs true; Staticmod.run ~dir () ];
    ]

is a possible ocsigenserver version of python3 -m http.server.

@balat
Copy link
Member

balat commented Jan 24, 2025

Thank you Sam! This is very useful.
This adds a dependency to Tyxml that should probably be added in dune-project/opam
Could we avoid this dependency?

Add a simple generator for directory listings:
- the listings are unstyled
- the generation must load the full directory (so that the entries can
  be sorted)
- consequently the generation should probably not be enabled when there
  are huge directories (which are usually a bad idea anyhow)
@shym
Copy link
Author

shym commented Jan 31, 2025

I’ve inlined the code from TyXML to avoid the dependency to escape text and I used Ocsigen_lib.Url.encode ~plus:false to encode the file names as URLs.
This made me think about the question of encoding for the text: no charset is set on the reply and it’s not completely clear to me what would be the best choice there (especially since file names can contain any bytes but two on POSIX OSes, so not all of them make sense as text). Could/should I enable a standard mechanism to set the charset, for instance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants