Why second request do not finish output?

≡放荡痞女 提交于 2019-12-13 04:47:38

问题


The browser wait for some data from server and logging is done only after server restart. Also I see may childs are forked.

$ah{ $r->hostname } ||=  HTML::Mason::ApacheHandler->new ( .. )

sub handle{
    eval{ $ah{ $r->hostname }->handle_request($r); };
    if( $@ ) {
    $r->filename( $r->document_root . '/errors/500.html' );
    $ah{ $r->hostname }->handle_request($r); };
    $r->log_error( 'ERROR' );
    }
}

What I do wrong so they are not finished?

UPD I have found only one note about same problem: http://sourceforge.net/p/mason/mailman/message/14999444/ but no clue.


回答1:


http://foertsch.name/ModPerl-Tricks/custom-content_type-with-custom_response.shtml

So, instead of passing the error text directly to custom_response we store it in pnotes and set an otherwise unused URI, say /-/error, as custom_response:

sub handler {
  my ($r)=@_;
  @{$r->pnotes}{qw/etext ect/}=("sorry, no access\n", 'text/plain; charset=my-characters');
  $r->custom_response( 403, "/-/error" );
  return 403;
}

Now, we need to configure /-/error to run a Perl handler:

<Location /-/error>
  SetHandler modperl
  PerlResponseHandler My::Error
</Location>

And, of course, we need the handler function, My::Error::handler:

sub handler {
  my ($r)=@_;
  return Apache2::Const::NOT_FOUND unless $r->prev;
  $r->content_type($r->prev->pnotes->{ect});
  $r->print($r->prev->pnotes->{etext});
  return Apache2::Const::OK;
}

This solution seems to work, but I do not know the answer from main question yet: Why request is not finished?

UPD

That seems a bug with mod_perl2 https://bz.apache.org/bugzilla/show_bug.cgi?id=57976




回答2:


Your handler doesn't return a proper value. Also, I'm not sure why you think attempting to handle the request a second time if the first one results in an error is a good idea so I have commented that out.

sub handle{
    my $result = eval{ $ah{ $r->hostname }->handle_request($r); };
    if( $@ ) {
      $r->filename( $r->document_root . '/errors/500.html' );
      # $ah{ $r->hostname }->handle_request($r); };
      $r->log_error( 'ERROR' );
    }
    return $result;
}


来源:https://stackoverflow.com/questions/30402391/why-second-request-do-not-finish-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!