Corion / WWW-Mechanize-Chrome

automate the Chrome browser

Home Page:https://metacpan.org/release/WWW-Mechanize-Chrome

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HTTP::Response from ->get does not return content

KES777 opened this issue · comments

    36: sub url2pdf {
   x37:     my $chrome =  shift->chrome;
   x38:     my $res =  $chrome->get( shift );
   x39:     DB::x;
  >>40:     $res->is_success  &&  $res->content   or return;
   x41:     return $chrome->content_as_pdf( format => 'A4' );
    42: }
    43:

DBG>$res
HTTP::Response {
  _content => ,
  _headers => HTTP::Headers {
    content-length => 4561,
    content-type => text/html;charset=UTF-8,
    date => Mon, 27 May 2019 11:37:49 GMT,
    server => Mojolicious (Perl),
  },
  _msg => OK,
  _rc => 200,
  _request => undef,
}

DBG>$res->content


As you can see HTTP::Response object has 4561 bytes of content, but ->content returns nothing. Also _content is empty

Ouch! The response body is filled in asynchronously, so maybe you can circumvent the issue by waiting some time (1s should be well enough) as a workaround.

The real fix is to return a proxy object that blocks when the ->content (or ->decoded_content or whatever) methods are called to wait for the fetched content.

please put a note into documentation