Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
59 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,7 +65,20 @@ sub request { | |
} | ||
|
||
my $res = $self->SUPER::request(@args); | ||
$self->set_cache($uri, $res) if $res->code eq HTTP::Status::RC_OK; | ||
|
||
## return cached data if it is "Not Modified" | ||
if ($res->code eq HTTP::Status::RC_NOT_MODIFIED) { | ||
my $not_modified_res = HTTP::Response->parse($obj->{as_string}); | ||
# hrm.. should we use '200 OK' here? | ||
$not_modified_res->code(HTTP::Status::RC_NOT_MODIFIED); | ||
$not_modified_res->message(HTTP::Status::status_message(HTTP::Status::RC_NOT_MODIFIED)); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
sekimura
Author
Owner
|
||
return $not_modified_res; | ||
} | ||
|
||
## cache only "200 OK" content | ||
if ($res->code eq HTTP::Status::RC_OK) { | ||
$self->set_cache($uri, $res); | ||
} | ||
|
||
return $res; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I see how this would make sense, because from the real site you are requesting, the real response code is 304, but...
Since the idea is to return the original response body content from the cache, I preferred keeping the original status code (in this case its mostly going to be 200, maybe consider caching other ones as well?). Then any code that uses the library down stream can be ignorant to the caching, in theory.