-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
86 lines (62 loc) · 2.53 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
NAME
Nginx::HTTP - asynchronous http client for nginx-perl
SYNOPSIS
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'}";
...
};
DESCRIPTION
Fast and simple asynchronous http client for nginx-perl. Supports
keepalive.
EXPORT
ngx_http
ngx_http_client
FUNCTIONS
"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.:
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].
$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.
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 "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'}";
...
};
SEE ALSO
Nginx, HTTP::Parser2::XS
AUTHOR
Alexandr Gomoliako <[email protected]>
LICENSE
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.