Lines 255-261
sub pagination_bar {
Link Here
|
255 |
|
255 |
|
256 |
=item output_with_http_headers |
256 |
=item output_with_http_headers |
257 |
|
257 |
|
258 |
&output_with_http_headers($query, $cookie, $data, $content_type[, $status]) |
258 |
&output_with_http_headers($query, $cookie, $data, $content_type[, $status[, $extra_options]]) |
259 |
|
259 |
|
260 |
Outputs $data with the appropriate HTTP headers, |
260 |
Outputs $data with the appropriate HTTP headers, |
261 |
the authentication cookie $cookie and a Content-Type specified in |
261 |
the authentication cookie $cookie and a Content-Type specified in |
Lines 267-278
$content_type is one of the following: 'html', 'js', 'json', 'xml', 'rss', or 'a
Link Here
|
267 |
|
267 |
|
268 |
$status is an HTTP status message, like '403 Authentication Required'. It defaults to '200 OK'. |
268 |
$status is an HTTP status message, like '403 Authentication Required'. It defaults to '200 OK'. |
269 |
|
269 |
|
|
|
270 |
$extra_options is hashref. If the key 'force_no_caching' is present and has |
271 |
a true value, the HTTP headers include directives to force there to be no |
272 |
caching whatsoever. |
273 |
|
270 |
=cut |
274 |
=cut |
271 |
|
275 |
|
272 |
sub output_with_http_headers { |
276 |
sub output_with_http_headers { |
273 |
my ( $query, $cookie, $data, $content_type, $status ) = @_; |
277 |
my ( $query, $cookie, $data, $content_type, $status, $extra_options ) = @_; |
274 |
$status ||= '200 OK'; |
278 |
$status ||= '200 OK'; |
275 |
|
279 |
|
|
|
280 |
$extra_options //= {}; |
281 |
|
276 |
my %content_type_map = ( |
282 |
my %content_type_map = ( |
277 |
'html' => 'text/html', |
283 |
'html' => 'text/html', |
278 |
'js' => 'text/javascript', |
284 |
'js' => 'text/javascript', |
Lines 285-297
sub output_with_http_headers {
Link Here
|
285 |
); |
291 |
); |
286 |
|
292 |
|
287 |
die "Unknown content type '$content_type'" if ( !defined( $content_type_map{$content_type} ) ); |
293 |
die "Unknown content type '$content_type'" if ( !defined( $content_type_map{$content_type} ) ); |
|
|
294 |
my $cache_policy = 'no-cache'; |
295 |
$cache_policy .= ', no-store, max-age=0' if $extra_options->{force_no_caching}; |
288 |
my $options = { |
296 |
my $options = { |
289 |
type => $content_type_map{$content_type}, |
297 |
type => $content_type_map{$content_type}, |
290 |
status => $status, |
298 |
status => $status, |
291 |
charset => 'UTF-8', |
299 |
charset => 'UTF-8', |
292 |
Pragma => 'no-cache', |
300 |
Pragma => 'no-cache', |
293 |
'Cache-Control' => 'no-cache', |
301 |
'Cache-Control' => $cache_policy, |
294 |
}; |
302 |
}; |
|
|
303 |
$options->{expires} = 'now' if $extra_options->{force_no_caching}; |
304 |
|
295 |
$options->{cookie} = $cookie if $cookie; |
305 |
$options->{cookie} = $cookie if $cookie; |
296 |
if ($content_type eq 'html') { # guaranteed to be one of the content_type_map keys, else we'd have died |
306 |
if ($content_type eq 'html') { # guaranteed to be one of the content_type_map keys, else we'd have died |
297 |
$options->{'Content-Style-Type' } = 'text/css'; |
307 |
$options->{'Content-Style-Type' } = 'text/css'; |
Lines 308-315
sub output_with_http_headers {
Link Here
|
308 |
} |
318 |
} |
309 |
|
319 |
|
310 |
sub output_html_with_http_headers { |
320 |
sub output_html_with_http_headers { |
311 |
my ( $query, $cookie, $data, $status ) = @_; |
321 |
my ( $query, $cookie, $data, $status, $extra_options ) = @_; |
312 |
output_with_http_headers( $query, $cookie, $data, 'html', $status ); |
322 |
output_with_http_headers( $query, $cookie, $data, 'html', $status, $extra_options ); |
313 |
} |
323 |
} |
314 |
|
324 |
|
315 |
|
325 |
|