POE-Component-Server-SimpleHTTP

 view release on metacpan or  search on metacpan

Changes.old  view on Meta::CPAN


	Kwalitee fixes.

* 1.15	

	Changed SSLify to require instead of use.

* 1.14

	Changed the defaults for the Prefork and SSLify to 'no'. 
	Applied streaming support patches from eriam.
	Converted Makefile.PL to Module::Install.

* 1.13

	learned about the difference between ref $self and ref( $self )
	Kwalitee-related fixes

* 1.12

	Finally use a Changes file - thanks RT #18981

Changes.svn  view on Meta::CPAN

2007-03-21 18:02:05 1.23
========================

  2007-03-21 17:59:56 (r34) by avinash240
  lib/POE/Component/Server/SimpleHTTP.pm M

    Bumping up version number.

  2007-03-21 17:54:25 (r33) by avinash240; Makefile.PL M

    Fixing build requirement issues for streaming tests.

========================
2007-03-21 08:44:13 1.22
========================

  2007-03-21 08:42:20 (r31) by bingos
  lib/POE/Component/Server/SimpleHTTP.pm M; MANIFEST M; Changes M

    Added files to MANIFEST. Bumped version number for release. 

  2007-03-20 18:39:13 (r30) by eriam; t/6_stream.t A

    + test for streaming ..

  2007-03-19 19:36:47 (r29) by eriam
  lib/POE/Component/Server/SimpleHTTP.pm M

    + pod and modified parameters passed to the stream event (everything
    is contained in a hash)

  2007-03-19 19:34:41 (r28) by eriam; examples/stream.pl A

    sample of the streaming feature

  2007-03-16 10:49:44 (r27) by eriam
  lib/POE/Component/Server/SimpleHTTP.pm M

    + test for streamed wheel + POST stream event to foreign session

  2007-03-16 10:48:09 (r26) by eriam
  lib/POE/Component/Server/SimpleHTTP/Response.pm M

    added STREAM_SESSION to allow other POE session to register the

Changes.svn  view on Meta::CPAN

  tools A; Changes.old A; lib/POE/Component/Server/SimpleHTTP.pm M;
  META.yml D; MANIFEST M; tools/svn-log.perl A; Changes R

    Added LOGHANDLER directive for general logging duties. Deprecated the
    Changes to Changes.old, added svn logging for the future Changes
    file. 

  2007-02-05 21:36:44 (r8) by eriam
  lib/POE/Component/Server/SimpleHTTP/Response.pm M

    ! is_streaming

  2007-02-03 19:02:35 (r7) by eriam
  lib/POE/Component/Server/SimpleHTTP.pm M

    + is_streaming needs a 1 to be initialized

  2007-02-03 19:01:03 (r6) by eriam
  lib/POE/Component/Server/SimpleHTTP/Response.pm M

    ! is_streaming can now be used to test if a response is actually in
    streaming mode

========================
2007-01-29 15:13:13 1.16
========================

  2007-01-29 15:07:26 (r4) by bingos
  lib/POE/Component/Server/SimpleHTTP.pm M; MANIFEST M; Changes M; inc D

    Kwalitee fixes

Makefile.PL  view on Meta::CPAN

  "POE" => "1.0000",
  "POE::Filter::HTTP::Parser" => "1.06",
  "Socket" => 0,
  "Storable" => 0,
  "Sys::Hostname" => 0,
  "Test::More" => "0.47",
  "Test::POE::Client::TCP" => "1.24"
);

# inserted by Dist::Zilla::Plugin::DynamicPrereqs 0.040
test_requires('POE::Component::Client::HTTP', '0.82') if prompt_default_no('Do you want to test streaming ( requires POE::Component::Client::HTTP )');
requires('POE::Component::SSLify', '0.04') if prompt_default_no('Do you want SSL support ( requires POE::Component::SSLify )');


unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) {
  delete $WriteMakefileArgs{TEST_REQUIRES};
  delete $WriteMakefileArgs{BUILD_REQUIRES};
  $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs;
}

delete $WriteMakefileArgs{CONFIGURE_REQUIRES}

README  view on Meta::CPAN

                      Close the listening socket
                      Kills all pending requests by closing their sockets
                      Removes it's alias
      
              With an argument of 'GRACEFUL', SimpleHTTP does this:
                      Close the listening socket
                      Waits for all pending requests to come in via DONE/CLOSE, then removes it's alias

    STREAM

              With a $response argument it streams the content and calls back the streaming event
              of the user's session (or with the dont_flush option you're responsible for calling
              back your session's streaming event).
      
              To use the streaming feature see below.

 Streaming with SimpleHTTP

    It's possible to send data as a stream to clients (unbuffered and
    integrated in the POE loop).

    Just create your session to receive events from SimpleHTTP as usually
    and add a streaming event, this event will be triggered over and over
    each time you set the $response to a streaming state and once you
    trigger it:

       # sets the response as streamed within our session which alias is HTTP_GET
       # with the event GOT_STREAM
       $response->stream(
          session     => 'HTTP_GET',
          event       => 'GOT_STREAM',
          dont_flush  => 1
       );
    
       # then you can simply yield your streaming event, once the GOT_STREAM event
       # has reached its end it will be triggered again and again, until you
       # send a CLOSE event to the kernel with the appropriate response as parameter
       $kernel->yield('GOT_STREAM', $response);

    The optional dont_flush option gives the user the ability to control
    the callback to the streaming event, which means once your stream event
    has reached its end it won't be called, you have to call it back.

    You can now send data by chunks and either call yourself back (via POE)
    or shutdown when your streaming is done (EOF for example).

       sub GOT_STREAM {
          my ( $kernel, $heap, $response ) = @_[KERNEL, HEAP, ARG0];
    
          # sets the content of the response
          $response->content("Hello World\n");
    
          # send it to the client
          POE::Kernel->post('HTTPD', 'STREAM', $response);
    
          # if we have previously set the dont_flush option
          # we have to trigger our event back until the end of
          # the stream like this (that can be a yield, of course):
          #
          # $kernel->delay('GOT_STREAM', 1, $stream );
    
          # otherwise the GOT_STREAM event is triggered continuously until
          # we call the CLOSE event on the response like that :
          #
          if ($heap{'streaming_is_done'}) {
             # close the socket and end the stream
             POE::Kernel->post('HTTPD', 'CLOSE', $response );
          }
       }

    The dont_flush option is there to be able to control the frequency of
    flushes to the client.

 SimpleHTTP Notes

dist.ini  view on Meta::CPAN

name = POE-Component-Server-SimpleHTTP
version = 2.30
author = Apocalypse <APOCAL@cpan.org>
license = Perl_5
copyright_holder = Apocalypse, Chris Williams, Eriam Schaffter, Marlon Bailey and Philip Gwyn

[@BINGOS]

[DynamicPrereqs]
-delimiter = |
-raw = |test_requires('POE::Component::Client::HTTP', '0.82') if prompt_default_no('Do you want to test streaming ( requires POE::Component::Client::HTTP )');
-raw = |requires('POE::Component::SSLify', '0.04') if prompt_default_no('Do you want SSL support ( requires POE::Component::SSLify )');

[Prereqs / ConfigureRequires]
ExtUtils::MakeMaker = 0

[Prereqs / TestRequires]
ExtUtils::MakeMaker = 6.59
POE::Filter::HTTP::Parser = 1.06
Test::More = 0.47
Test::POE::Client::TCP = 1.24

examples/stream.pl  view on Meta::CPAN

	$_[KERNEL]->post( 'HTTPD', 'DONE', $response );
}

sub GOT_STREAM {
   my ( $kernel, $heap, $stream ) = @_[KERNEL, HEAP, ARG0];
   
   # the stream hash contains the wheel, the request, the response 
   # and an id associated the the wheel
   $stream->{'wheel'}->put("Hello World\n");

   # lets go on streaming ...
   POE::Kernel->delay('GOT_STREAM', 1, $stream );
}

lib/POE/Component/Server/SimpleHTTP.pm  view on Meta::CPAN

   );

   if ( DEBUG and keys %{ $self->_connections } ) {

      # use Data::Dumper;
      warn "conn id=", $wheel->ID, " [",
        join( ', ', keys %{ $self->_connections } ), "]";
   }

   # Save this wheel!
   # 0 = wheel, 1 = Output done?, 2 = SimpleHTTP::Response object, 3 == request, 4 == streaming?
   $self->_requests->{ $wheel->ID } = 
	POE::Component::Server::SimpleHTTP::State->new( wheel => $wheel );

   # Debug stuff
   if (DEBUG) {
      warn "Got_Connection completed creation of ReadWrite wheel ( "
        . $wheel->ID . " )";
   }

   # Success!

lib/POE/Component/Server/SimpleHTTP.pm  view on Meta::CPAN

# 'Got_Flush'
# Finished with a request!
event 'got_flush' => sub {
   my ($kernel,$self,$id) = @_[KERNEL,OBJECT,ARG0];

   return unless defined $self->_requests->{$id};

   # Debug stuff
   warn "Got Flush event for wheel ID ( $id )" if DEBUG;

   if ( $self->_requests->{$id}->streaming ) {
      # Do the stream !
      warn "Streaming in progress ...!" if DEBUG;
      return;
   }

   # Check if we are shutting down
   if ( $self->_requests->{$id}->done ) {

      if ( $self->must_keepalive( $id ) ) {
         warn "Keep-alive id=$id ..." if DEBUG;

lib/POE/Component/Server/SimpleHTTP.pm  view on Meta::CPAN

   unless ( $self->_requests->{$id}->wheel_alive ) {
      warn 'Tried to send data over a closed/nonexistant socket!' if DEBUG;
      $kernel->post(
         $self->errorhandler->{SESSION},
         $self->errorhandler->{EVENT},
         'Socket closed/nonexistant !'
      ) if $self->errorhandler and $self->errorhandler->{SESSION} and $self->errorhandler->{EVENT};
      return;
   }

   # Check if we were streaming. 

   if ( $self->_requests->{$id}->streaming ) {
      $self->_requests->{$id}->set_streaming(0);
      $self->_requests->{$id}->set_done(1); # Finished streaming
      # TODO: We might not get a flush, trigger it ourselves.
      if ( !$self->_requests->{$id}->wheel->get_driver_out_messages ) {
         $kernel->yield( 'got_flush', $id );
      }
      return;
   }
   

   $self->fix_headers( $response );

lib/POE/Component/Server/SimpleHTTP.pm  view on Meta::CPAN

      ) if $self->errorhandler and $self->errorhandler->{SESSION} and $self->errorhandler->{EVENT};
      return;
   }

   $self->fix_headers( $response, 1 );

   # Sets the correct POE::Filter
   unless ( defined $response->IS_STREAMING ) {

      # Mark this socket done
      $self->_requests->{$id}->set_streaming(1);
      $response->set_streaming(1);
   }

   if (DEBUG) {
      warn "Sending stream via "
        . $response->STREAM_SESSION . "/"
        . $response->STREAM
        . " with id $id \n";
   }

   if ( $self->_chunkcount->{$id} > 1 ) {

lib/POE/Component/Server/SimpleHTTP.pm  view on Meta::CPAN

      $wheel->set_output_filter( POE::Filter::Stream->new() );
      $wheel->put( $response->content );
   }
   else {
      my $wheel = $self->_requests->{ $response->_WHEEL }->wheel;
      $wheel->set_output_filter( $wheel->get_input_filter() );
      $wheel->put($response);
   }

   # we send the event to stream with wheels request and response to the session
   # that has registered the streaming event
   unless ( $response->DONT_FLUSH ) {
      $kernel->post(
         $response->STREAM_SESSION,    # callback session
         $response->STREAM,            # callback event
         $self->_responses->{ $response->_WHEEL }
      );
   }

   # Success!
   return 1;

lib/POE/Component/Server/SimpleHTTP.pm  view on Meta::CPAN

   # Delete it!
   delete $self->_requests->{$id};
   delete $self->_responses->{$id};

   warn 'Delete references to the connection done.' if DEBUG;

   # All done!
   return 1;
};

# Registers a POE inline state (primarly for streaming)
event 'REGISTER' => sub {
   my ( $session, $state, $code_ref ) = @_[ SESSION, ARG0 .. ARG1 ];
   warn 'Registering state in POE session' if DEBUG;
   return $session->register_state( $state, $code_ref );
};

# SETCLOSEHANDLER
event 'SETCLOSEHANDLER' => sub {
   my ($self,$sender) = @_[OBJECT,SENDER ];
   my ($connection,$state,@params) = @_[ARG0..$#_];

lib/POE/Component/Server/SimpleHTTP.pm  view on Meta::CPAN

		Close the listening socket
		Kills all pending requests by closing their sockets
		Removes it's alias

	With an argument of 'GRACEFUL', SimpleHTTP does this:
		Close the listening socket
		Waits for all pending requests to come in via DONE/CLOSE, then removes it's alias

=item C<STREAM>

	With a $response argument it streams the content and calls back the streaming event
	of the user's session (or with the dont_flush option you're responsible for calling
        back your session's streaming event).

	To use the streaming feature see below.

=back

=head2 Streaming with SimpleHTTP

It's possible to send data as a stream to clients (unbuffered and integrated in the
POE loop).

Just create your session to receive events from SimpleHTTP as usually and add a
streaming event, this event will be triggered over and over each time you set the
$response to a streaming state and once you trigger it:

   # sets the response as streamed within our session which alias is HTTP_GET
   # with the event GOT_STREAM
   $response->stream(
      session     => 'HTTP_GET',
      event       => 'GOT_STREAM',
      dont_flush  => 1
   );

   # then you can simply yield your streaming event, once the GOT_STREAM event
   # has reached its end it will be triggered again and again, until you
   # send a CLOSE event to the kernel with the appropriate response as parameter
   $kernel->yield('GOT_STREAM', $response);

The optional dont_flush option gives the user the ability to control the callback
to the streaming event, which means once your stream event has reached its end
it won't be called, you have to call it back.

You can now send data by chunks and either call yourself back (via POE) or
shutdown when your streaming is done (EOF for example).

   sub GOT_STREAM {
      my ( $kernel, $heap, $response ) = @_[KERNEL, HEAP, ARG0];

      # sets the content of the response
      $response->content("Hello World\n");

      # send it to the client
      POE::Kernel->post('HTTPD', 'STREAM', $response);

      # if we have previously set the dont_flush option
      # we have to trigger our event back until the end of
      # the stream like this (that can be a yield, of course):
      #
      # $kernel->delay('GOT_STREAM', 1, $stream );

      # otherwise the GOT_STREAM event is triggered continuously until
      # we call the CLOSE event on the response like that :
      #
      if ($heap{'streaming_is_done'}) {
         # close the socket and end the stream
         POE::Kernel->post('HTTPD', 'CLOSE', $response );
      }
   }

The dont_flush option is there to be able to control the frequency of flushes
to the client.

=head2 SimpleHTTP Notes

lib/POE/Component/Server/SimpleHTTP/Response.pm  view on Meta::CPAN


has 'STREAM_DONE' => (
  is => 'ro',
  default => sub { 0 },
  writer => 'set_stream_done',
  init_arg => undef,
);

has 'IS_STREAMING' => (
  is => 'ro',
  writer => 'set_streaming',
);

has 'DONT_FLUSH' => (
  is => 'rw',
  isa => 'Bool',
);

sub new {
   my $class = shift;

lib/POE/Component/Server/SimpleHTTP/State.pm  view on Meta::CPAN

);

has 'done' => (
  is => 'ro',
  isa => 'Bool',
  init_arg => undef,
  default => sub { 0 },
  writer => 'set_done',
);

has 'streaming' => (
  is => 'ro',
  isa => 'Bool',
  init_arg => undef,
  default => sub { 0 },
  writer => 'set_streaming',
);

sub reset {
  my $self = shift;
  $self->clear_response;
  $self->clear_request;
  $self->set_streaming(0);
  $self->set_done(0);
  $self->wheel->set_output_filter( $self->wheel->get_input_filter ) if $self->has_wheel;
  return 1;
}

sub close_wheel {
  my $self = shift;
  return unless $self->has_wheel;
  $self->wheel->shutdown_input;
  $self->wheel->shutdown_output;

t/06_stream.t  view on Meta::CPAN

   $_[KERNEL]->call( $_[SENDER], 'SETCLOSEHANDLER', $c, 'on_close', $c->ID );
    
    # We are done!
   $kernel->yield('GOT_STREAM', $response);
   return;
}

sub GOT_STREAM {
   my ( $kernel, $heap, $response ) = @_[KERNEL, HEAP, ARG0];

   # lets go on streaming ...
   if ($heap->{'count'} <= 2) {
      my $text = "Hello World ".$heap->{'count'}." \n";
      #print "send ".$text."\n";
      $response->content($text);
      
      $heap->{'count'}++;
      POE::Kernel->post('HTTPD', 'STREAM', $response);
   }
   else {
      $STREAMS{ $response->connection->ID }--;



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