-# overrides existing Danga::Socket method
-sub event_write {
- my ($self) = @_;
- # only continue watching for readability when we are done writing:
- return if $self->write(undef) != 1;
-
- if ($self->{rbuf} eq '') { # wait for next request
- $self->watch_read(1);
- } else { # avoid recursion for pipelined requests
- push @$pipelineq, $self;
- $next_tick ||= Danga::Socket->AddTimer(0, *process_pipelineq);
+sub response_write {
+ my ($self, $env, $res) = @_;
+ my $alive = response_header_write($self, $env, $res);
+ if (defined(my $body = $res->[2])) {
+ if (ref $body eq 'ARRAY') {
+ if ($alive == 2) {
+ chunked_write($self, $_) for @$body;
+ } else {
+ identity_write($self, $_) for @$body;
+ }
+ response_done($self, $alive);
+ } else {
+ $self->{forward} = $body;
+ $self->{alive} = $alive;
+ getline_pull($self); # kick-off!
+ }
+ # these are returned to the calling application:
+ } elsif ($alive >= 2) {
+ bless [ $self, $alive ], 'PublicInbox::HTTP::Chunked';
+ } else {
+ bless [ $self, $alive ], 'PublicInbox::HTTP::Identity';