| 1 | package Apache::Tika::Connection::Future; | ||
| 2 | use 5.020; | ||
| 3 | use Future::HTTP; | ||
| 4 | use Moo; | ||
| 5 | with 'Apache::Tika::Connection'; | ||
| 6 | |||
| 7 | #use Filter::signatures; | ||
| 8 | use feature 'signatures'; | ||
| 9 | no warnings 'experimental::signatures'; | ||
| 10 | |||
| 11 | our $VERSION = '0.11'; | ||
| 12 | |||
| 13 | has ua => ( | ||
| 14 | is => 'ro', | ||
| 15 | default => sub { | ||
| 16 | return Future::HTTP->new() | ||
| 17 | }, | ||
| 18 | ); | ||
| 19 | |||
| 20 | sub request( $self, $method, $url, $content, @headers ) { | ||
| 21 | # Should initialize | ||
| 22 | |||
| 23 | $method = uc $method; | ||
| 24 | |||
| 25 | my $content_size = length $content; | ||
| 26 | |||
| 27 | # 'text/plain' for the language | ||
| 28 | my %headers= ( | ||
| 29 | "Content-Length" => $content_size, | ||
| 30 | "Accept" => 'application/json,text/plain', | ||
| 31 | 'Content-Type' => 'application/octet-stream', | ||
| 32 | @headers | ||
| 33 | ); | ||
| 34 | |||
| 35 | $self->ua->http_request( | ||
| 36 | $method => $url, | ||
| 37 | persistent => 1, | ||
| 38 | headers => \%headers, | ||
| 39 | body => $content, | ||
| 40 | )->then(sub( $body, $headers ) { | ||
| 41 | # The headers might be invalid! | ||
| 42 | my ( $code, $response ) = $self->process_response( | ||
| 43 | undef, # request | ||
| 44 | delete $headers->{Status}, # code | ||
| 45 | delete $headers->{Reason}, # msg | ||
| 46 | $body, # body | ||
| 47 | $headers # headers | ||
| 48 | ); | ||
| 49 | Future->done( $code, $response ) | ||
| 50 | }); | ||
| 51 | } | ||
| 52 | |||
| 53 | 1; | ||
| 54 | |||
| 55 | =head1 REPOSITORY | ||
| 56 | |||
| 57 | The public repository of this module is | ||
| 58 | L<https://github.com/Corion/Apache-Tika-Async>. | ||
| 59 | |||
| 60 | =head1 SUPPORT | ||
| 61 | |||
| 62 | The public support forum of this module is | ||
| 63 | L<https://perlmonks.org/>. | ||
| 64 | |||
| 65 | =head1 BUG TRACKER | ||
| 66 | |||
| 67 | Please report bugs in this module via the RT CPAN bug queue at | ||
| 68 | L<https://rt.cpan.org/Public/Dist/Display.html?Name=Apache-Tika-Async> | ||
| 69 | or via mail to L<apache-tika-async-Bugs@rt.cpan.org>. | ||
| 70 | |||
| 71 | =head1 AUTHOR | ||
| 72 | |||
| 73 | Max Maischein C<corion@cpan.org> | ||
| 74 | |||
| 75 | =head1 COPYRIGHT (c) | ||
| 76 | |||
| 77 | Copyright 2014-2019 by Max Maischein C<corion@cpan.org>. | ||
| 78 | |||
| 79 | =head1 LICENSE | ||
| 80 | |||
| 81 | This module is released under the same terms as Perl itself. | ||
| 82 | |||
| 83 | =cut |