Nginx::HTTP - asynchronous http client for nginx-perl
use Nginx; use Nginx::HTTP; ngx_http "1.2.3.4:80", "GET / HTTP/1.1" . "\x0d\x0a" . "Host: localhost" . "\x0d\x0a" . "" . "\x0d\x0a" , sub { my ($headers, $buf_ref) = @_; unless ($headers) { ngx_log_error $!, "error"; return; } ngx_log_notice 0, "got $headers->{'_status'}"; ... };
Fast and simple asynchronous http client for nginx-perl. Supports keepalive.
ngx_http ngx_http_client
ngx_http "$ip:$port:key=value;key=value...", $request, sub { }
Establishes new connection with $ip:$port and sends raw HTTP request. $request should be either scalar or scalar reference. Additionally there are two options available: timeout and ssl. E.g.:
$ip:$port
$request
timeout
ssl
ngx_http "1.2.3.4:443:ssl=1;timeout=15", ... ngx_http "1.2.3.4:80:timeout=15", ... ngx_http "1.2.3.4:80", ...
Calls back with parsed response header in $_[0] and scalar reference to the body in $_[1].
$_[0]
$_[1]
$headers = { _status => 503, content-type => ['text/html'], content-length => [1234], ... }; $body = \"foobar";
$body is cleared right after the callback, so you have to copy its content if you want to use it later.
$body
On error calls back without any arguments. Tries to reconnect on the next request.
For now every connection is cached forever. But you can use ngx_http_client to create desired caching behaviour.
ngx_http_client
ngx_http "1.2.3.4:80", "GET / HTTP/1.1" . "\x0d\x0a" . "Host: localhost" . "\x0d\x0a" . "" . "\x0d\x0a" , sub { my ($headers, $body_ref) = @_; unless ($headers) { ngx_log_error $!, "error"; return; } ngx_log_notice 0, "got $headers->{'_status'}"; ... };
Nginx, HTTP::Parser2::XS
Alexandr Gomoliako <zzz@zzz.org.ua>
Copyright 2012 Alexandr Gomoliako. All rights reserved.
This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.
To install Nginx::HTTP, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Nginx::HTTP
CPAN shell
perl -MCPAN -e shell install Nginx::HTTP
For more information on module installation, please visit the detailed CPAN module installation guide.