File Share

Live on this server

Password protected directory listing with resumable downloads.

FileShareSample.cs37 lines
using GenHTTP.Api.Content;

using GenHTTP.Modules.Authentication;
using GenHTTP.Modules.DirectoryBrowsing;
using GenHTTP.Modules.IO;

public static class FileShareSample
{

    public static IHandlerBuilder Create()
    {
        /*
         *
         * Shares a folder with friends: they log in with their browser, browse
         * through the files and download them. Downloads of large files can be
         * paused and resumed, as range requests are supported.
         *
         * Open /samples/file-share/ and log in as "friend" / "secret".
         *
         * See https://genhttp.org/documentation/content/handlers/listing/
         * and https://genhttp.org/documentation/content/concerns/range-support/
         *
         */

        // the files shipped with this website (resources/samples/files),
        // use ResourceTree.FromDirectory("/srv/share") to share a directory
        var files = Resources.Tree("samples/files");

        var auth = BasicAuthentication.Create()
                                      .Add("friend", "secret");

        return Listing.From(files)
                      .AddRangeSupport()
                      .Authentication(auth);
    }

}

Try it

Send the requests to the sample running on this server - change the path, headers or body as you like, or copy them as curl commands.

  1. Browse the files

    Log in as "friend" with password "secret".

    PAGE /samples/file-share/ Open
  2. Download the first 100 bytes of a file

    206 Partial Content

    GET
    Headers
    curl -i -H 'Authorization: Basic ZnJpZW5kOnNlY3JldA==' -H 'Range: bytes=0-99' 'https://genhttp.org/samples/file-share/README.md'