App-lupapona

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

1.06

- guess MIME type based on file extension (that is, .txt files are no
  longer served as text/gemini, you need to use .gmi, or some other
  file extension File::MimeInfo doesn't know about)

- new dependency: File::MimeInfo

- use --text_encoding=euc-jp to override UTF-8 charset for all text
  files (all "text" types)

1.04

- Should work for more than one file, now! 😅

1.00

- New to CPAN

README.md  view on Meta::CPAN

- [Limitations](#limitations)
- [Dependencies](#dependencies)
- [Quickstart](#quickstart)
- [Troubleshooting](#troubleshooting)
- [Options](#options)
- [Using systemd](#using-systemd)
- [Privacy](#privacy)

## Limitations

Currently, all files are served as `text/gemini; charset=UTF-8`.

## Dependencies

Perl libraries you need to install if you want to run Lupa Pona:

- [Mojo::Log](https://metacpan.org/pod/Mojo%3A%3ALog) and [Mojo::IOLoop](https://metacpan.org/pod/Mojo%3A%3AIOLoop), or `libmojolicious-perl`
- [IO::Socket::SSL](https://metacpan.org/pod/IO%3A%3ASocket%3A%3ASSL), or `libio-socket-ssl-perl`
- [File::Slurper](https://metacpan.org/pod/File%3A%3ASlurper), or `libfile-slurper-perl`
- [Modern::Perl](https://metacpan.org/pod/Modern%3A%3APerl), or `libmodern-perl-perl`
- [URI::Escape](https://metacpan.org/pod/URI%3A%3AEscape), or `liburi-escape-xs-perl`

README.md  view on Meta::CPAN


This starts the server in the foreground, for `gemini://localhost:1965`. If it
aborts, see the ["Troubleshooting"](#troubleshooting) section below. If it runs, open your
favourite Gemini client and test it, or open another terminal and test it:

    echo gemini://localhost \
      | openssl s_client --quiet --connect localhost:1965 2>/dev/null

You should see a Gemini page starting with the following:

    20 text/gemini; charset=UTF-8
    Welcome to Lupa Pona!

Success!! 😀 🚀🚀

## Troubleshooting

No trouble, yet!

## Options

script/lupa-pona  view on Meta::CPAN

hosting. It's a wiki, not just a file server.

Let me know if you want to use Lupa Pona in a multi-user or virtual-hosting
setup. All the necessary bits can be lifted from elsewhere. Right now, I'm just
using Lupa Pona to temporarily serve a local directory, as one might
occasionally use a few lines of Python to serve the local directory over the web
using C<SimpleHTTPServer>.

=head2 Limitations

Currently, all files are served as C<text/gemini; charset=UTF-8>.

=head2 Dependencies

Perl libraries you need to install if you want to run Lupa Pona:

=over

=item L<Mojo::Log> and L<Mojo::IOLoop>, or C<libmojolicious-perl>

=item L<IO::Socket::SSL>, or C<libio-socket-ssl-perl>

script/lupa-pona  view on Meta::CPAN


This starts the server in the foreground, for C<gemini://localhost:1965>. If it
aborts, see the L</Troubleshooting> section below. If it runs, open your
favourite Gemini client and test it, or open another terminal and test it:

    echo gemini://localhost \
      | openssl s_client --quiet --connect localhost:1965 2>/dev/null

You should see a Gemini page starting with the following:

    20 text/gemini; charset=UTF-8
    Welcome to Lupa Pona!

Success!! 😀 🚀🚀

=head2 Troubleshooting

No trouble, yet!

=head2 Options

script/lupa-pona  view on Meta::CPAN

    $log->debug("The URL is empty");
    $stream->write("59 URL expected\r\n");
  } elsif (length($url) > 1024) {
    $log->debug("The URL is too long");
    $stream->write("59 The URL is too long\r\n");
  } elsif ($authority and $host and $host ne $url_host or $port ne $url_port) {
    $stream->write("53 Unsupported proxy request for $url; we just serve $host:$port\r\n");
  } elsif (not $path) {
    $stream->write("31 $url/\r\n"); # enforce trailing slash
  } elsif ($path eq "/") {
    $stream->write("20 text/gemini; charset=UTF-8\r\n");
    $stream->write("Welcome to Lupa Pona!\n");
    for (read_dir(".")) {
      next if $_ eq $cert_file;
      next if $_ eq $key_file;
      next if /~$/; # Emacs backup files
      $stream->write("=> $_\n") if -f;
    }
  } elsif ($path eq "/$cert_file" or $path eq "/$key_file") {
    $stream->write("50 Forbidden\n");
  } elsif ($path =~ m!^/([^/]+)$!) {
    my $file = decode_utf8(uri_unescape($1));
    if (-f $file) {
      my $mime = globs($file) || mime_type($file);
      $mime .= "; charset=$encoding" if $mime =~ /^text\// and $encoding;
      $stream->write("20 $mime\r\n");
      $stream->write(read_binary($file));
    } else {
      $stream->write("51 File not found: $file\r\n");
    }
  } else {
    $log->info("No handler for $url");
    $stream->write("59 Don't know how to handle $url\r\n");
  }
  $stream->close_gracefully();

t/basic.t  view on Meta::CPAN

    eval { query_gemini("gemini://$host:$port/") };
  } else {
    $ok = 1;
    last;
  }
}

die "$!: giving up after ${total}s\n" unless $ok;

my $page = query_gemini("gemini://$host:$port/");
like($page, qr"^20 text/gemini; charset=UTF-8\r\n", "Gemini header");
like($page, qr/Welcome to Lupa Pona!/, "Title");
like($page, qr/=> basic\.t/, "basic.t");
like($page, qr/=> test\.gmi/, "test.gmi");
like($page, qr/=> test\.txt/, "test.txt");
is(scalar(() = $page =~ m/=>/g), 3, "three links");

$page = query_gemini("gemini://$host:$port/basic.t");
# the MIME type can be application/x-perl or text/troff, depending on the system
# the test runs on…
like($page, qr"^20 (application/x-perl|text/(troff|gemini); charset=UTF-8)\r\n", "File header");
like($page, qr"GNU General Public License", "File content");

$page = query_gemini("gemini://$host:$port/test.txt");
like($page, qr"^20 text/plain; charset=UTF-8\r\n", "File header");
like($page, qr"Alex Schröder", "File content");

$page = query_gemini("gemini://$host:$port/test.gmi");
like($page, qr"^20 text/gemini; charset=UTF-8\r\n", "File header");
like($page, qr"Hallo", "File content");

$page = query_gemini("gemini://$host:$port/cert.pem");
like($page, qr"^50 ", "Do not serve cert.pem");

$page = query_gemini("gemini://127.0.0.1:$port/");
like($page, qr"^53 ", "Do not proxy");

done_testing();



( run in 0.286 second using v1.01-cache-2.11-cpan-4d50c553e7e )