diff --git a/lib/App/htmlcat.pm b/lib/App/htmlcat.pm
index 22d6333..6f72026 100644
--- a/lib/App/htmlcat.pm
+++ b/lib/App/htmlcat.pm
@@ -7,6 +7,7 @@ use HTML::Entities;
use Data::Section::Simple qw(get_data_section);
use IO::Socket::INET;
use Plack::Runner;
+use Encode;
our $VERSION = '0.01';
@@ -61,16 +62,10 @@ sub broadcast {
}
}
-sub boundary {
- my $self = shift;
- return $self->{boundary} ||= join '_', 'htmlcat', $$, time;
-}
-
sub push_line {
my ($self, $handle, $line) = @_;
- $handle->push_write("Content-Type: application/json; charset=utf-8\n\n");
- $handle->push_write(json => { html => scalar $self->{ansi}->html($line) });
- $handle->push_write('--' . $self->boundary . "\n");
+ $handle->push_write("data:" . Encode::encode("utf-8", scalar $self->{ansi}->html($line) ) );
+ $handle->push_write("\n");
}
sub as_psgi {
@@ -89,9 +84,10 @@ sub as_psgi {
my $writer = $respond->([
200,
- [ 'Content-Type' => sprintf 'multipart/mixed; charset=utf-8; boundary="%s"', $self->boundary ]
+ [ 'Content-Type' => 'text/event-stream; charset=utf-8',
+ 'Cache-Control' => 'no-cache'
+ ]
]);
- $writer->write('--' . $self->boundary . "\n");
my $io = $env->{'psgix.io'};
my $handle = AnyEvent::Handle->new(
@@ -182,11 +178,12 @@ __DATA__
@@ -219,131 +214,7 @@ window.onload = function () {