Skip to content

Commit

Permalink
[#1048] Add a no_cache argument to DW::Routing
Browse files Browse the repository at this point in the history
This (on apache, at least), will add Cache-control: no-cache, and
Pragma: no-cache
  • Loading branch information
afuna committed Nov 8, 2014
1 parent 6fc3d54 commit 614e054
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cgi-bin/DW/Request.pm
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ Spawn off an external program.
Redirect to a different URL.
=head2 C<< $r->no_cache >>
Turn off caching for this resource.
=head1 AUTHORS
=over
Expand Down
5 changes: 5 additions & 0 deletions cgi-bin/DW/Request/Apache2.pm
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,9 @@ sub spawn {
return $self->{r}->spawn_proc_prog( @_ );
}

sub no_cache {
my DW::Request::Apache2 $self = shift;
return $self->{r}->no_cache( 1 );
}

1;
3 changes: 3 additions & 0 deletions cgi-bin/DW/Request/Standard.pm
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,7 @@ sub spawn {
confess "Sorry, spawning not implemented.";
}

sub no_cache {
confess "Sorry, no_cache not implemented.";
}
1;
4 changes: 4 additions & 0 deletions cgi-bin/DW/Routing.pm
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ sub _call_hash {
$r->content_type( $default_content_types->{$format} )
if $default_content_types->{$format};

# apply no-cache if needed
$r->no_cache if $opts->no_cache;

# try to call the handler that actually does the content creation; it will
# return either a number (HTTP code), or undef
# means there was an error of some sort
Expand Down Expand Up @@ -596,6 +599,7 @@ sub _apply_defaults {
$hash->{api} = $opts->{api} || 0;
$hash->{format} ||= $opts->{format} || 'html';
$hash->{prefer_ssl} = $opts->{prefer_ssl} || 0;
$hash->{no_cache} = $opts->{no_cache} || 0;

my $formats = $opts->{formats} || [ $hash->{format} ];
$formats = { map { ( $_, 1 ) } @$formats } if ref $formats eq 'ARRAY';
Expand Down
7 changes: 7 additions & 0 deletions cgi-bin/DW/Routing/CallInfo.pm
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ Should prefer SSL if possible.

sub prefer_ssl { return $_[0]->{__hash}->{prefer_ssl} || 0; }

=head2 C<< $self->no_cache >>
Return whether we should prevent caching or not.
=cut
sub no_cache { return $_[0]->{__hash}->{no_cache} || 0; }

=head2 C<< $self->subpatterns >>
Return the regex matches.
Expand Down

0 comments on commit 614e054

Please sign in to comment.