/usr/share/perl5/Perlbal/Manual/Hooks.pod is in libperlbal-perl 1.80-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | =head1 NAME
Perlbal::Manual::Hooks - How Perlbal's hooks work
=head2 VERSION
Perlbal 1.78.
=head2 DESCRIPTION
Basically, a hook is a bit of code that is run at certain stages in the requests that Perlbal handles.There are all kinds of hooks available and they all do different things. Some are only applicable to some of the roles and others are applicable only to certain classes. Each hook is described in detail below, but first a description of the basics of a hook.
In general, you define a hook by calling the C<register_hook> method on a L<Perlbal::Service> object. You specify what hook you are interested in and provide a reference to a subroutine that will be called with the parameters particular to that hook.
There are three types of hooks:
=head2 Global hooks
These are hooks that are defined on a global scale. They are set like so:
Perlbal::register_global_hook('foo', sub { return 0; });
That would define a global hook named foo that would return 0 when it's called. (Return codes from hooks will be explained below)
Global hooks are useful to define management commands. See C<manage_command> under L<Perlbal::Manual::Plugins> for more information.
=head2 Service handler hooks
A handler hook is attached to a particular service. These hooks are called one at a time until one hook returns 1. At that point, no further hooks are called. For example:
$service->register_hook('bar', sub {
# do something
return 1;
});
When this hook runs, it would return 1, signalling to Perlbal that it had done what it needed to do and that Perlbal shouldn't call any further hooks. You can use this type of hook to create sets of plugins that all handle different types of requests, and when one hook had handled a request it wouldn't continue telling other hooks about the request.
=head3 backend_client_assigned
Happens right after a backend is assigned to a client, but before we've talked to the backend and asked it to do something. If you return a true value, the process is stopped and you will manually have to send the client's request to the backend, etc.
Called in L<Perlbal::BackendHTTP>.
Available in role C<reverse_proxy>.
=head3 backend_readable_verify
When the backend is about to start sending the response.
Called in L<Perlbal::BackendHTTP>.
Available in all roles.
=head3 backend_response_received
Called as soon as response headers are read from the backend. If you return a true value, will stop all handling at that point.
Called in L<Perlbal::BackendHTTP>.
Available in all roles.
=head3 backend_write_verify
When the backend is ready to receive the request.
Called in L<Perlbal::BackendHTTP>.
Available in all roles.
=head3 concat_get_poststat_file_missing
Called when a missing file was requested in a request for multiple files concatenated, right before sending the 404 response. Return a true value to overtake the connection.
Called in L<Perlbal::ClientHTTPBase>.
Available in role C<web_server>.
See also C<concat_get_poststat_pre_send>, C<static_get_poststat_file_missing> and C<static_get_poststat_pre_send>.
=head3 concat_get_poststat_pre_send
Called when the resulting file of a request for multiple files concatenated is about to be sent, right before the 200 response code is added as a header. Return a true value to overtake the connection.
Called in L<Perlbal::ClientHTTPBase>.
Available in role C<web_server>.
See also C<concat_get_poststat_file_missing>, C<static_get_poststat_file_missing> and C<static_get_poststat_pre_send>.
=head3 handle_put
Called when handling a PUT request.
Called in L<Perlbal::ClientHTTP>.
Available in role C<web_server>.
=head3 make_high_priority
Called when a request is received and right before we're about to determine if this request is high priority or not. Return a true value to make the request high priority; false to leave it alone. Note that this is only called when the request isn't already high priority due to cookie priority scheduling, which is done inside L<Perlbal::Service>.
Called in L<Perlbal::ClientProxy>.
Available in all roles.
=head3 make_low_priority
Called when a request is received and right before we're about to determine if this request is high priority or not. Return a true value to make the request low priority; false to leave it alone.
Called in L<Perlbal::ClientProxy>.
Available in all roles.
=head3 modify_response_headers
Called when we've set all the headers, and are about to serve a file. You can change or add response headers at this point, or cancel the process by returning a true value. You will have to send the response to the client yourself if you do this.
Called in L<Perlbal::ClientHTTPBase>.
Available in role C<web_server>.
=head3 proxy_read_request
Called on the request before we send the request to a backend.
Called in L<Perlbal::ClientProxy>.
Available in all roles.
=head3 put_writeout
Called when there is some put data to write out.
Called in L<Perlbal::ClientHTTP>.
Available in role C<web_server>.
=head3 reproxy_fh_finished
Called when a reproxy file has completed and is about to close the file handle. You can cancel the process by returning a true value (in which case you will have to close the reproxy_fh yourself).
Called in L<Perlbal::ClientHTTPBase>.
Available in role C<web_server>.
=head3 reproxy_response_received
Called as soon as response headers are read from a reproxied backend. If you return a true value, will stop all handling at that point.
Called in L<Perlbal::ClientProxy>.
Available in role C<reverse_proxy>.
=head3 return_to_base
Called when a request has been finished, and control of the Client* object is about to be transferred back to ownership by a service selector. Return a true value if the perlbal core action in this situation should be bypassed.
Called in L<Perlbal::ClientHTTPBase>.
Available in all roles.
=head3 start_file_reproxy
Called when we've been told to reproxy a file. If you return a true value, Perlbal will not perform any operations on the file and will simply return. You can also change the file in the scalar ref passed as the second parameter.
Called in L<Perlbal::ClientProxy>; receives C<$filename_ref>, a reference to the filename.
Available in role C<reverse_proxy>.
=head3 start_http_request
A generic hook that works for both webserver and proxy modes, run after either the specific C<start_proxy_request> or C<start_web_request> hooks below. Like those, you return true from this hook to takeover the connection.
Called in L<Perlbal::ClientProxy> and L<Perlbal::ClientHTTP>.
Available in roles C<reverse_proxy> and C<web_server>.
=head3 start_proxy_request
Called as soon as we've read in headers from a user but right before we've requested a backend connection. If a true value is returned, Perlbal will not request a backend.
Called in L<Perlbal::ClientProxy>.
Available in role C<reverse_proxy>.
=head3 start_send_file
Called when we've opened a file and are about to start sending it to the user using sendfile. Return a true value to cancel the default sending.
Called in L<Perlbal::ClientHTTPBase>.
Available in role C<web_server>.
=head3 start_serve_request
Called when we're about to serve a local file, before we've done any work. You can change the file served by modifying C<$uri_ref>, or cancel the process by returning a true value.
Called in L<Perlbal::ClientHTTPBase>; receives C<$uri_ref>, a reference to the URI.
Available in role C<web_server>.
=head3 start_web_request
When a service has gotten headers and is about to serve it. Return a true value to cancel the default handling of web requests.
Called in L<Perlbal::ClientHTTP>.
Available in role C<web_server>.
=head3 static_get_poststat_file_missing
Called when a missing static single file was requested, right before sending the 404 response. Return a true value to overtake the connection.
Called in L<Perlbal::ClientHTTPBase>.
Available in role C<web_server>.
See also C<concat_get_poststat_file_missing>, C<concat_get_poststat_pre_send> and C<static_get_poststat_pre_send>.
=head3 static_get_poststat_pre_send
Called when a static single file is about to be sent, right before the 200 response code is added as a header. Return a true value to overtake the connection.
Called in L<Perlbal::ClientHTTPBase>.
Available in role C<web_server>.
See also C<concat_get_poststat_file_missing>, C<concat_get_poststat_pre_send> and C<static_get_poststat_file_missing>.
=head2 Service general hooks
These hooks are defined the same way as above, but general hooks are all run. The return code is ignored. This can be useful for putting in code that records statistics about an action or something to that effect.
=head3 end_proxy_request
This hook is called when the L<Perlbal::ClientProxy> object is being closed.
Available in role C<reverse_proxy>.
=head2 SEE ALSO
L<Perlbal::Manual::Internals>, L<Perlbal::Manual::Plugins>.
|