Mojolicious

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

    can use the config helper instead. Unfortunately there is no good way to warn users, so this deprecation will be in
    effect until the next major release.
  - Deprecated Mojo::Collection::slice since nobody remembers anymore what its intended purpose was.
  - Added EXPERIMENTAL proxy->get_p, proxy->post_p and proxy->start_p helpers to Mojolicious::Plugin::DefaultHelpers.
  - Added EXPERIMENTAL dehop method to Mojo::Headers.
  - Added EXPERIMENTAL bytes_waiting and can_write methods to Mojo::IOLoop::Stream.
  - Added EXPERIMENTAL high_water_mark attribute to Mojo::IOLoop::Stream.
  - Updated bundled TLS certificate.
  - Improved Mojo::Base flags not to require a certain order.
  - Improved clone performance in Mojo::Headers by 100%.
  - Improved streaming response performance slightly.
  - Fixed a typo in the 425 status message in Mojo::Message::Response. (CandyAngel)
  - Fixed a missing deprecation warning in Mojo::Promise. (marcus)

8.17  2019-05-23
  - Fixed a bug in Mojo::UserAgent where the request timeout would not work for keep-alive requests. (ilmari)

8.16  2019-05-14
  - Improved Mojo::Headers to reject characters in header values that would corrupt the HTTP message.
  - Fixed getopt function in Mojo::Util to behave more like GetOptionsFromArray. (jberger, reneeb)

lib/Mojolicious/Guides/Cookbook.pod  view on Meta::CPAN


  use Mojo::UserAgent;
  use Mojo::Asset::File;

  # Add "stream" generator
  my $ua = Mojo::UserAgent->new;
  $ua->transactor->add_generator(stream => sub ($transactor, $tx, $path) {
    $tx->req->content->asset(Mojo::Asset::File->new(path => $path));
  });

  # Send multiple files streaming via PUT and POST
  $ua->put('http://example.com/upload'  => stream => '/home/sri/mojo.png');
  $ua->post('http://example.com/upload' => stream => '/home/sri/minion.png');

The C<json>, C<form> and C<multipart> content generators are always available.

  use Mojo::UserAgent;

  # Send "application/json" content via PATCH
  my $ua = Mojo::UserAgent->new;
  my $tx = $ua->patch('http://api.example.com' => json => {foo => 'bar'});

lib/Mojolicious/Guides/Cookbook.pod  view on Meta::CPAN

  use Mojo::UserAgent;

  # Upload file via POST and "multipart/form-data"
  my $ua = Mojo::UserAgent->new;
  $ua->post('example.com/upload' => form => {image => {file => '/home/sri/hello.png'}});

And once again you don't have to worry about memory usage, all data will be streamed directly from the file.

=head2 Streaming response

Receiving a streaming response can be really tricky in most HTTP clients, but L<Mojo::UserAgent> makes it actually
easy.

  use Mojo::UserAgent;

  # Accept responses of indefinite size
  my $ua = Mojo::UserAgent->new(max_response_size => 0);

  # Build a normal transaction
  my $tx = $ua->build_tx(GET => 'http://example.com');

lib/Mojolicious/Guides/Cookbook.pod  view on Meta::CPAN

  });

  # Process transaction
  $tx = $ua->start($tx);

The event L<Mojo::Content/"read"> will be emitted for every chunk of data that is received, even chunked transfer
encoding and gzip content encoding will be handled transparently if necessary.

=head2 Streaming request

Sending a streaming request is almost just as easy.

  use Mojo::UserAgent;

  # Build a normal transaction
  my $ua = Mojo::UserAgent->new;
  my $tx = $ua->build_tx(POST => 'http://example.com');

  # Prepare body
  my $body = 'Hello World!';
  $tx->req->headers->content_length(length $body);

t/mojolicious/longpolling_lite_app.t  view on Meta::CPAN

};

subtest 'Custom response' => sub {
  $t->get_ok('/longpoll/dynamic')
    ->status_is(201)
    ->header_is(Server => 'Mojolicious (Perl)')
    ->header_like('Set-Cookie' => qr/baz=yada/)
    ->content_is('Dynamic!');
};

subtest 'Chunked response streaming with drain event' => sub {
  my $stash = undef;
  $t->app->plugins->once(before_dispatch => sub { $stash = shift->stash });
  $t->get_ok('/stream')->status_is(200)->header_is(Server => 'Mojolicious (Perl)')->content_is('0123456789');
  is $stash->{subscribers}, 0, 'no leaking subscribers';
  ok $stash->{destroyed}, 'controller has been destroyed';
};

subtest 'Rendering of template' => sub {
  my $stash = undef;
  $t->app->plugins->once(before_dispatch => sub { $stash = shift->stash });



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