Changeset 62 in bookmarks
- Timestamp:
- 08/23/13 17:26:14 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BookmarkController.pm
r61 r62 265 265 $feed->title($title); 266 266 267 my $feed_uri = URI->new_abs('feed', $self->base_uri);268 $feed_uri->query_form(tag => \@tags);269 $feed->id($feed_uri->canonical);270 271 267 for my $link ($self->_get_list_links('application/atom+xml', { q => $query, tag => \@tags })) { 272 268 my $atom_link = XML::Atom::Link->new; … … 308 304 } 309 305 306 #TODO: better method name 307 # returns 1 if there is an If-Modified-Since header and it is newer than the given $mtime 308 # returns 0 if there is an If-Modified-Since header but the $mtime is newer 309 # returns undef if there is no If-Modified-Since header 310 sub _check_modified { 311 my $self = shift; 312 my $mtime = shift; 313 314 # check If-Modified-Since header to return cache response 315 if ($self->request->env->{HTTP_IF_MODIFIED_SINCE}) { 316 my $cache_time = str2time($self->request->env->{HTTP_IF_MODIFIED_SINCE}); 317 return $mtime <= $cache_time ? 1 : 0; 318 } else { 319 return; 320 } 321 } 322 310 323 sub view { 311 324 my ($self, $id) = @_; … … 315 328 my $bookmark = $self->get_bookmark({ id => $id }); 316 329 if ($bookmark) { 317 # check If-Modified-Since header to return cache response 318 if ($self->request->env->{HTTP_IF_MODIFIED_SINCE}) { 319 my $cache_time = str2time($self->request->env->{HTTP_IF_MODIFIED_SINCE}); 320 if ($bookmark->mtime <= $cache_time) { 321 return [304, [], []]; 322 } 323 } 330 return [304, [], []] if $self->_check_modified($bookmark->mtime); 331 324 332 my $last_modified = time2str($bookmark->mtime); 325 333 … … 348 356 my ($self, $id, $field) = @_; 349 357 350 my $bookmark = $self-> bookmarks->get_bookmark({ id => $id });358 my $bookmark = $self->get_bookmark({ id => $id }); 351 359 if ($bookmark) { 360 return [304, [], []] if $self->_check_modified($bookmark->mtime); 361 352 362 # respond with just the requested field as plain text 353 363 my $value = eval { $bookmark->$field }; … … 359 369 } 360 370 } 361 return [200, ['Content-Type' => 'text/plain; charset=UTF-8'], [ref $value eq 'ARRAY' ? join(' ', @{ $value }) : $value]]; 371 my $last_modified = time2str($bookmark->mtime); 372 return [200, ['Content-Type' => 'text/plain; charset=UTF-8', 'Last-Modified' => $last_modified], [ref $value eq 'ARRAY' ? join(' ', @{ $value }) : $value]]; 362 373 } else { 363 374 return [404, ['Content-Type' => 'text/plain; charset=UTF-8'], ["Boomark $id not found"]];
Note: See TracChangeset
for help on using the changeset viewer.