| 1 | [](https://github.com/fangfufu/httpdirfs/actions/workflows/codeql.yml) |
| 2 | [](https://www.codefactor.io/repository/github/fangfufu/httpdirfs) |
| 3 | [](https://app.codacy.com/gh/fangfufu/httpdirfs/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade) |
| 4 | [](https://sonarcloud.io/summary/new_code?id=fangfufu_httpdirfs) |
| 5 | [](https://results.pre-commit.ci/latest/github/fangfufu/httpdirfs/master) |
| 6 | |
| 7 | # HTTPDirFS - HTTP Directory Filesystem with a permanent cache, and Airsonic / Subsonic server support |
| 8 | |
| 9 | Have you ever wanted to mount those HTTP directory listings as if it was a |
| 10 | partition? Look no further, this is your solution. HTTPDirFS stands for Hyper |
| 11 | Text Transfer Protocol Directory Filesystem. |
| 12 | |
| 13 | The performance of the program is excellent. HTTP connections are reused through |
| 14 | curl-multi interface. The FUSE component runs in the multithreaded mode. |
| 15 | |
| 16 | There is a permanent cache system which can cache all the file segments you have |
| 17 | downloaded, so you don't need to these segments again if you access them later. |
| 18 | This feature is triggered by the `--cache` flag. This is similar to the |
| 19 | `--vfs-cache-mode full` feature of |
| 20 | [rclone mount](https://rclone.org/commands/rclone_mount/#vfs-cache-mode-full) |
| 21 | |
| 22 | The cache system runs multiple background worker threads to process downloads |
| 23 | asynchronously, allowing multiple concurrent HTTP connections to download |
| 24 | different file segments in parallel. |
| 25 | |
| 26 | There is support for Airsonic / Subsonic server. This allows you to mount a |
| 27 | remote music collection locally. |
| 28 | |
| 29 | If you enable the `--external-links` flag, HTTPDirFS will also parse the HTML |
| 30 | directory listing of the mounted server and identify any `<a href>` tags |
| 31 | pointing to absolute external (cross-origin) URLs. These external files and |
| 32 | directories will appear alongside local files in the mountpoint. External URLs |
| 33 | ending with a trailing slash (`/`) are treated as directories; navigating into |
| 34 | them triggers a recursive layout discovery on the remote server. |
| 35 | |
| 36 | If you only want to access a single file, there is also a simplified Single File |
| 37 | Mode. This can be especially useful if the web server does not present a HTTP |
| 38 | directory listing. |
| 39 | |
| 40 | ## Usage |
| 41 | |
| 42 | Basic usage: |
| 43 | |
| 44 | ``` |
| 45 | ./httpdirfs -f --cache $URL $MOUNT_POINT |
| 46 | ``` |
| 47 | |
| 48 | An example URL would be |
| 49 | [Debian CD Image Server](https://cdimage.debian.org/debian-cd/). The `-f` flag |
| 50 | keeps the program in the foreground, which is useful for monitoring which URL |
| 51 | the filesystem is visiting. |
| 52 | |
| 53 | For more usage related help, run |
| 54 | |
| 55 | ``` |
| 56 | ./httpdirfs --help |
| 57 | ``` |
| 58 | |
| 59 | or |
| 60 | |
| 61 | ``` |
| 62 | man httpdirfs |
| 63 | ``` |
| 64 | |
| 65 | Please note that the man page only works if you have installed HTTPDirFS |
| 66 | properly. |
| 67 | |
| 68 | The full usage flags is also documented in the [usage](USAGE.md) page. |
| 69 | |
| 70 | ## Compilation |
| 71 | |
| 72 | For important development related documentation, please refer |
| 73 | [src/README.md](src/README.md). |
| 74 | |
| 75 | ### Debian 13 "Trixie" |
| 76 | |
| 77 | Under Debian 13 "Trixie" and newer versions, you need the following |
| 78 | dependencies: |
| 79 | |
| 80 | ``` |
| 81 | libgumbo-dev libfuse3-dev libssl-dev libcurl4-openssl-dev uuid-dev help2man |
| 82 | libexpat1-dev pkg-config meson clang-format |
| 83 | ``` |
| 84 | |
| 85 | You can then compile the program similar to how you compile a typical program |
| 86 | that uses the Meson build system: |
| 87 | |
| 88 | ``` |
| 89 | meson setup builddir |
| 90 | cd builddir |
| 91 | meson compile |
| 92 | ``` |
| 93 | |
| 94 | To install the program, do the following: |
| 95 | |
| 96 | ``` |
| 97 | sudo meson install |
| 98 | ``` |
| 99 | |
| 100 | To uninstall the program, do the following: |
| 101 | |
| 102 | ``` |
| 103 | sudo ninja uninstall |
| 104 | ``` |
| 105 | |
| 106 | To clean the build directory, run: |
| 107 | |
| 108 | ``` |
| 109 | ninja clean |
| 110 | ``` |
| 111 | |
| 112 | For more information, please refer to this |
| 113 | [tutorial](https://mesonbuild.com/Tutorial.html). |
| 114 | |
| 115 | ### macOS |
| 116 | |
| 117 | Under macOS, you can use [Homebrew](https://brew.sh/) to install the |
| 118 | dependencies: |
| 119 | |
| 120 | ``` |
| 121 | brew install gumbo-parser openssl curl expat meson pkg-config ossp-uuid |
| 122 | brew install --cask macfuse |
| 123 | ``` |
| 124 | |
| 125 | To compile the program, you might need to set the `PKG_CONFIG_PATH` so that |
| 126 | `meson` can find `openssl`: |
| 127 | |
| 128 | ``` |
| 129 | export PKG_CONFIG_PATH="$(brew --prefix openssl@3)/lib/pkgconfig:$(brew --prefix)/lib/pkgconfig:$PKG_CONFIG_PATH" |
| 130 | meson setup builddir |
| 131 | cd builddir |
| 132 | meson compile |
| 133 | ``` |
| 134 | |
| 135 | Please note that while macOS build instructions are provided, macOS build |
| 136 | testing is primarily done via GitHub Actions CI, as I do not have regular access |
| 137 | to a physical Mac. |
| 138 | |
| 139 | ### Other operating systems |
| 140 | |
| 141 | I don't have the resources to test out compilation for Linux distributions other |
| 142 | than Debian. I also do not have the resources to test out compilation for |
| 143 | FreeBSD. Therefore, I have removed the instruction on how to compile for FreeBSD |
| 144 | in the README for now. Please feel free to send me a pull request to add them |
| 145 | back in. It is known that HTTPDirFS |
| 146 | [does compile](https://github.com/fangfufu/httpdirfs/issues/165) on FreeBSD. |
| 147 | |
| 148 | ## Installation |
| 149 | |
| 150 | ### Debian 13 "Trixie" |
| 151 | |
| 152 | HTTPDirFS is developed on Debian, and it is available as a package in Debian 13 |
| 153 | "Trixie". If you are on Debian Trixie, you can simply run the following command |
| 154 | as `root`: |
| 155 | |
| 156 | ``` |
| 157 | apt install httpdirfs |
| 158 | ``` |
| 159 | |
| 160 | For more information on the status of HTTDirFS in Debian, please refer to |
| 161 | [Debian package tracker](https://tracker.debian.org/pkg/httpdirfs-fuse) |
| 162 | |
| 163 | ### Other distributions |
| 164 | |
| 165 | Please note if you install HTTDirFS from a repository, it may be outdated. |
| 166 | |
| 167 | [](https://repology.org/project/fusefs%3Ahttpdirfs/versions) |
| 168 | |
| 169 | ## Airsonic / Subsonic server support |
| 170 | |
| 171 | The Airsonic / Subsonic server support is dedicated the my Debian package |
| 172 | maintainer Jerome Charaoui.You can mount the music collection on your Airsonic / |
| 173 | Subsonic server (\*sonic), and browse them using your favourite file browser. |
| 174 | |
| 175 | You simply have to supply both `--sonic-username` and `--sonic-password` to |
| 176 | trigger the \*sonic server mode. For example: |
| 177 | |
| 178 | ``` |
| 179 | ./httpdirfs -f --cache --sonic-username $USERNAME --sonic-password $PASSWORD $URL $MOUNT_POINT |
| 180 | ``` |
| 181 | |
| 182 | You definitely want to enable the cache for this one, otherwise it is painfully |
| 183 | slow. |
| 184 | |
| 185 | There are two ways of mounting your \*sonic server |
| 186 | |
| 187 | - the index mode |
| 188 | - and the ID3 mode. |
| 189 | |
| 190 | In the index mode, the filesystem is presented based on the listing on the |
| 191 | `Index` link in your \*sonic's home page. |
| 192 | |
| 193 | In ID3 mode, the filesystem is presented using the following hierarchy: 0. Root |
| 194 | |
| 195 | 1. Alphabetical indices of the artists' names |
| 196 | 1. The artists' names |
| 197 | 1. All of the albums by a single artist |
| 198 | 1. All the songs in an album. |
| 199 | |
| 200 | By default, \*sonic server is mounted in the index mode. If you want to mount in |
| 201 | ID3 mode, please use the `--sonic-id3` flag. |
| 202 | |
| 203 | Please note that the cache feature is unaffected by how you mount your \*sonic |
| 204 | server. If you mounted your server in index mode, the cache is still valid in |
| 205 | ID3 mode, and vice versa. |
| 206 | |
| 207 | HTTPDirFS is also known to work with the following applications, which implement |
| 208 | some or all of Subsonic API: |
| 209 | |
| 210 | - [Funkwhale](https://funkwhale.audio/) (requires `--sonic-id3` and |
| 211 | `--no-range-check`, more information in |
| 212 | [issue #45](https://github.com/fangfufu/httpdirfs/issues/45)) |
| 213 | - [LMS](https://github.com/epoupon/lms) (requires `--sonic-insecure` and |
| 214 | `--no-range-check`, more information in |
| 215 | [issue #46](https://github.com/fangfufu/httpdirfs/issues/46). To mount the |
| 216 | [demo instance](https://lms-demo.poupon.dev/), you might also need |
| 217 | `--insecure-tls`) |
| 218 | - [Navidrome](https://github.com/navidrome/navidrome), more information in |
| 219 | [issue #51](https://github.com/fangfufu/httpdirfs/issues/51). |
| 220 | |
| 221 | ## Single file mode |
| 222 | |
| 223 | If you just want to access a single file, you can specify `--single-file-mode`. |
| 224 | This effectively creates a virtual directory that contains one single file. This |
| 225 | operating mode is similar to the unmaintained |
| 226 | [httpfs](http://httpfs.sourceforge.net/). |
| 227 | |
| 228 | e.g. |
| 229 | |
| 230 | ``` |
| 231 | ./httpdirfs -f --cache --single-file-mode https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-11.0.0-amd64-netinst.iso mnt |
| 232 | ``` |
| 233 | |
| 234 | This can be useful if the web server does not present a HTTP directory listing. |
| 235 | This feature was implemented due to Github |
| 236 | [issue #86](https://github.com/fangfufu/httpdirfs/issues/86) |
| 237 | |
| 238 | ## Permanent cache system |
| 239 | |
| 240 | You can cache the files you have accessed permanently on your hard drive by |
| 241 | using the `--cache` flag. The file it caches persist across sessions, but can |
| 242 | clear the cache using `--cache-clear` |
| 243 | |
| 244 | > [!WARNING] |
| 245 | > If `--cache-location <dir>` appears before `--cache-clear`, the entire |
| 246 | > directory `<dir>` will be deleted instead. Take caution when specifying |
| 247 | > non-empty directories to be used as cache. |
| 248 | |
| 249 | By default, the cache files are stored under `${XDG_CACHE_HOME}/httpdirfs`, |
| 250 | `${HOME}/.cache/httpdirfs`, or the current working directory `./.cache`, |
| 251 | whichever is found first. By default, `${XDG_CACHE_HOME}/httpdirfs` is normally |
| 252 | `${HOME}/.cache/httpdirfs`. |
| 253 | |
| 254 | Each HTTP directory gets its own cache folder, they are named using the escaped |
| 255 | URL of the HTTP directory. |
| 256 | |
| 257 | Once a segment of the file has been downloaded once, it won't be downloaded |
| 258 | again. Subsequent reads are served offline at local storage speed. |
| 259 | |
| 260 | The permanent cache system relies on sparse allocation. Please make sure your |
| 261 | filesystem supports it. Otherwise your local storage device will get heavy I/O |
| 262 | from cache file creation. For a list of filesystem that supports sparse |
| 263 | allocation, please refer to |
| 264 | [Wikipedia](https://en.wikipedia.org/wiki/Comparison_of_file_systems#Allocation_and_layout_policies). |
| 265 | |
| 266 | ## Configuration file support |
| 267 | |
| 268 | This program has basic support for using a configuration file. By default, the |
| 269 | configuration file which the program reads is |
| 270 | `${XDG_CONFIG_HOME}/httpdirfs/config`, which by default is at |
| 271 | `${HOME}/.config/httpdirfs/config`. You will have to create the sub-directory |
| 272 | and the configuration file yourself. In the configuration file, please supply |
| 273 | one option per line. For example: |
| 274 | |
| 275 | ``` |
| 276 | --username test |
| 277 | --password test |
| 278 | -f |
| 279 | ``` |
| 280 | |
| 281 | Alternatively, you can specify your own configuration file by using the |
| 282 | `--config` option. |
| 283 | |
| 284 | ### Log levels |
| 285 | |
| 286 | You can control how much log HTTPDirFS outputs by setting the |
| 287 | `HTTPDIRFS_LOG_LEVEL` environmental variable. For details of the different types |
| 288 | of log that are supported, please refer to |
| 289 | [log.h](https://github.com/fangfufu/httpdirfs/blob/master/src/log.h) and |
| 290 | [log.c](https://github.com/fangfufu/httpdirfs/blob/master/src/log.c). |
| 291 | |
| 292 | ## The Technical Details |
| 293 | |
| 294 | For the normal HTTP directories, this program downloads the HTML web pages/files |
| 295 | using [libcurl](https://curl.haxx.se/libcurl/), then parses the listing pages |
| 296 | using [Gumbo](https://github.com/google/gumbo-parser), and presents them using |
| 297 | [libfuse](https://github.com/libfuse/libfuse). |
| 298 | |
| 299 | For \*sonic servers, rather than using the Gumbo parser, this program parses |
| 300 | \*sonic servers' XML responses using |
| 301 | [expat](https://github.com/libexpat/libexpat). |
| 302 | |
| 303 | The cache system stores the metadata and the downloaded file into two separate |
| 304 | directories. It uses `uint8_t` arrays to record which segments of the file had |
| 305 | been downloaded. |
| 306 | |
| 307 | Note that HTTPDirFS requires the server to support HTTP Range Request, some |
| 308 | servers support this features, but does not present `"Accept-Ranges: bytes` in |
| 309 | the header responses. HTTPDirFS by default checks for this header field. You can |
| 310 | disable this check by using the `--no-range-check` flag. |
| 311 | |
| 312 | ### Allowed characters in filenames |
| 313 | |
| 314 | The intended allowed character in filenames is the following: |
| 315 | |
| 316 | Filenames must: |
| 317 | |
| 318 | - Consists of printable characters |
| 319 | - Must not contain '/' in the middle of the filename. |
| 320 | - Must not end with '/'. |
| 321 | |
| 322 | Directories must: |
| 323 | |
| 324 | - Consists of printable characters |
| 325 | - Must not contain '/' in the middle of the directory name. |
| 326 | - Must end with '/'. |
| 327 | |
| 328 | The exact change that set these rules was done in commit |
| 329 | [647657169574bf7be29f858ff3d1a3a70d27d661](https://github.com/fangfufu/httpdirfs/commit/647657169574bf7be29f858ff3d1a3a70d27d661). |
| 330 | |
| 331 | ## Press Coverage |
| 332 | |
| 333 | - Linux Format - Issue [264](https://www.linuxformat.com/archives?issue=264), |
| 334 | July 2020 |
| 335 | |
| 336 | ## Contributors |
| 337 | |
| 338 | Thanks for your contribution to the project! |
| 339 | |
| 340 | [](https://github.com/fangfufu/httpdirfs/graphs/contributors) |
| 341 | [](https://github.com/fangfufu/httpdirfs/graphs/contributors) |
| 342 | |
| 343 | ## Special Acknowledgement |
| 344 | |
| 345 | - First of all, I would like to thank |
| 346 | [Jerome Charaoui](https://github.com/jcharaoui) for being the Debian |
| 347 | Maintainer for this piece of software. Thank you so much for packaging it! |
| 348 | - I would like to thank |
| 349 | [Cosmin Gorgovan](https://scholar.google.co.uk/citations?user=S7UZ6MAAAAAJ&hl=en) |
| 350 | for the technical and moral support. Your wisdom is much appreciated! |
| 351 | - I would like to thank [Edenist](https://github.com/edenist) for providing |
| 352 | FreeBSD compatibility patches. |
| 353 | - I would like to thank [hiliev](https://github.com/hiliev) for providing macOS |
| 354 | compatibility patches. |
| 355 | - I would like to thank [Jonathan Kamens](https://github.com/jikamens) for |
| 356 | providing a whole bunch of code improvements and the improved build system. |
| 357 | - I would like to thank [-Archivist](https://www.reddit.com/user/-Archivist/) |
| 358 | for not providing FTP or WebDAV access to his server. This piece of software |
| 359 | was written in direct response to his appalling behaviour. |
| 360 | |
| 361 | ## License |
| 362 | |
| 363 | This program is free software: you can redistribute it and/or modify it under |
| 364 | the terms of the GNU General Public License as published by the Free Software |
| 365 | Foundation, either version 3 of the License, or (at your option) any later |
| 366 | version. |
| 367 | |
| 368 | This program is distributed in the hope that it will be useful, but **WITHOUT |
| 369 | ANY WARRANTY**; without even the implied warranty of **MERCHANTABILITY** or |
| 370 | **FITNESS FOR A PARTICULAR PURPOSE**. See the GNU General Public License for |
| 371 | more details. |