1AnyEvent::HTTP::Server:U:sReerq(C3o)ntributed Perl DocumAennytEavteinotn::HTTP::Server::Req(3)
2
3
4
6 AnyEvent::HTTP::Server::Req - Request object used by
7 AnyEvent::HTTP::Server
8
10 Version 1.97
11
13 sub dispatch {
14 my $request = shift;
15 if ($request->path =~ m{ ^ /ping /? $}x) {
16 $request->reply( 200, 'pong', headers=> { 'Content-Type' => 'text/plain'});
17 } else {
18 $request->reply( 404, 'Not found', headers=> { 'Content-Type' => 'text/plain'});
19 }
20 }
21
23 This module is a part of AnyEvent::HTTP::Server, see perldoc AnyEvent::HTTP::Server for details
24
26 Does not export anything
27
29 connection - 'Connection' header
30 return Connection header from client request
31
32 method - request method
33 return HTTP Method been used in request, such as GET, PUT, HEAD, POST, etc..
34
35 full_uri - URI with host part
36 Requested uri with host and protocol name. Protocol part is always http://
37
38 uri - URI aith host part stripped from it
39 Requested uri without host and protocol name
40
41 headers - Headers from client request
42 Return value is a hash reference. All header names are lowercased.
43
44 go($location) - Send redirect
45 Redirect client to $location with 302 HTTP Status code.
46
47 reply($status,$content, $headers) - Send reply to client
48 This method sends both headers and response body to client, and should be called at the end of
49 request processing.
50
51 Parameters:
52
53 status
54
55 HTTP Status header (200 is OK, 403 is Auth required and so on).
56
57 content
58
59 Response body as a scalar.
60
61 headers
62
63 Response headers as a hash reference.
64
65 replyjs( [code], $data, %arguments ) - Send reply in JSON format
66 code
67
68 Optional Status code, 200 is default.
69
70 data
71
72 Response data to encode with JSON. All strings will be encoded as UTF-8.
73
74 arguments
75
76 List of key=> value arguments. The only supported argument for a moment is
77 pretty => 1 | 0. JSON data will be formated for easier reading by human,
78 if pretty is true.
79
80 send_headers($code, @argumnets_list ) - send response headers to client
81 This method may be used in conjunction with body() and finish() methods
82 for streaming content serving. Response header 'transfer-encoding' is set
83 to 'chunked' by this method.
84
85 code
86
87 HTTP Status code to send to a client.
88
89 arguments_list
90
91 The rest of arguments is interpreted as a key=>value list. One should pass
92 headers key, for example
93
94 $request->send_headers(200, headers => { 'Content-type' => 'text/plain'} );
95
96 Subsequent data should be send with body method, and after all data sent, finish
97 request handling with finish() method. Methods send_headers, body and finish
98 should be always used together.
99
100 body($data ) - send chunk of data to client
101 Sends part ( or chunk ) of data to client
102
103 finish - finish chunked request processing
104 Finishes request by sending zero-length chunk to client.
105
106 abort - drop chunked connection
107 Let client know if an error occured by dropping connection before sending complete data
108
109 KNOWN ISSUES: nginx, when used as a reverse proxy, masks connection abort, leaving no
110 ability for browser to detect error condition.
111
113 • GitHub repository
114
115 <http://github.com/Mons/AnyEvent-HTTP-Server-II>
116
118 • Thanks to Marc Lehmann for AnyEvent
119
120 • Thanks to Robin Redeker for AnyEvent::HTTPD
121
123 Mons Anderson, <mons@cpan.org>
124
126 This program is free software; you can redistribute it and/or modify it
127 under the terms of either: the GNU General Public License as published
128 by the Free Software Foundation; or the Artistic License.
129
130
131
132perl v5.34.0 2021-07-22 AnyEvent::HTTP::Server::Req(3)