App-Phoebe

 view release on metacpan or  search on metacpan

lib/App/Phoebe/Chat.pm  view on Meta::CPAN

  my $stream = shift;
  my $url = shift;
  success($stream);
  $stream->write("# Chat\n");
  $stream->write(
    encode_utf8
    "This server supports a Gemini-based chat. "
    . "If you don't have a dedicated client, you can use two windows of a regular Gemini client. "
    . "Visit the following two URLs. "
    . "The first one allows you “listen” to the channel and the second one allows you to “say” things. "
    . "The connection to the “listen” channel needs a streaming client. "
    . "Use a client certificate with the same common name for both connections.\n");
  $stream->write("=> $url/listen\r\n");
  $stream->write("=> $url/say\r\n");
}

sub process_chat_say {
  my $stream = shift;
  my $host = shift;
  my $port = shift;
  my $space = shift;

lib/App/Phoebe/Ijirait.pm  view on Meta::CPAN


# Save the world every half hour.
Mojo::IOLoop->recurring(1800 => \&save_world);

# Streaming needs a special handler because the stream never closes.
unshift(@request_handlers, "^gemini://(?:$host)(?:\\d+)?/play/ijirait/stream" => \&add_streamer);

sub add_streamer {
  my $stream = shift;
  my $data = shift;
  $log->debug("Handle streaming request");
  $log->debug("Discarding " . length($data->{buffer}) . " bytes")
      if $data->{buffer};
  my $url = $data->{request};
  my $port = App::Phoebe::port($stream);
  if ($url =~ m!^(?:gemini:)?//($host)(?::$port)?/play/ijirait/stream$!) {
    my $p = login($stream);
    if ($p) {
      # 1h timeout
      $stream->timeout(3600);
      # remove from channel members if an error happens

lib/App/Phoebe/Oddmuse.pm  view on Meta::CPAN

  my $space = shift;
  my $id = shift;
  my $revision = shift;
  my $url = "$oddmuse_wikis{$host}";
  $url .= "/$space" if $space;
  $url .= "/raw/" . uri_escape_utf8($id);
  $url .= "?revision=$revision" if $revision;
  return oddmuse_get_raw($stream, $url);
}

# It would be cool if this were streaming...
sub oddmuse_get_raw {
  my $stream = shift;
  my $url = shift;
  $log->debug("Requesting $url");
  my $ua = Mojo::UserAgent->new;
  my $res = $ua->get($url => {'X-Forwarded-For' => $stream->handle->peerhost})->result;
  if ($res->is_success) {
    return $res->text;
  } elsif ($res->code == 404) {
    return "";

t/WebEdit.t  view on Meta::CPAN

my $page = query_web("GET /page/Hello HTTP/1.0\r\n"
		     . "host: $host:$port");
like($page, qr/^HTTP\/1.1 200 OK/, "Page served via HTTP");
like($page, qr/This page does not yet exist/, "Empty page");

$page = query_web("GET /do/edit/Hello HTTP/1.0\r\n"
		  . "host: $host:$port");
like($page, qr/^HTTP\/1.1 200 OK/, "Edit page served via HTTP");

my $haiku = <<EOT;
The laptop streaming
videos of floods and rain
but I hear sparrows
EOT

my $content = "text=" . uri_escape_utf8("```\n$haiku```");
my $length = length($content);

$page = query_web("POST /do/edit/Hello HTTP/1.0\r\n"
		  . "host: $host:$port\r\n"
		  . "content-type: application/x-www-form-urlencoded\r\n"

t/WebEdit.t  view on Meta::CPAN


$page = query_web("POST /do/edit/Hello HTTP/1.0\r\n"
		  . "host: $host:$port\r\n"
		  . "content-type: application/x-www-form-urlencoded\r\n"
		  . "content-length: $length\r\n"
		  . "\r\n"
		  . $content);

like($page, qr/^HTTP\/1.1 302 Found/, "Redirect after save");
like(query_web("GET /page/Hello HTTP/1.0\r\nhost: $host:$port"),
     qr/The laptop streaming/, "Page saved");

done_testing;



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