Skip to content

[CacheResponsesPlugin] Serve out of cache. #442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed

Conversation

abhinavsingh
Copy link
Owner

@abhinavsingh abhinavsingh commented Oct 4, 2020

WIP: DO NOT MERGE

This pull request contains all the changes related to the cache server plugin, which is currently maintained under "cache-server" branch. Pull request gives us a running CI/CD for changes happening in "cache-server" branch (also helps in early detection of merge conflict may arise). Any core changes will be patched separately leaving this PR only with changes related to cache server. See individual commits underneath for all the PRs.

pasccom and others added 2 commits October 3, 2020 16:27
* Tests for cache file contents with embedded proxy.

* Attempt to use a separate file for each request

In fact, it will not, because the file name is generated from plugin
UID. A more advanced scheme is needed.

This is required if we want to create answers from cache.

* Create cache dir if it does not exist.

* Added a cache list file.

The cache list is a text file whose lines are composed of five
space-separated fields:
  - The HTTP(S) request method
  - The HTTP(S) request host
  - The HTTP(S) request path
  - A SHA512 sum of the request body, if any (else 'None').
  - The name of the cache file.

* Support for multi-processing in cache store.

Since the list file will be shared accross all processes, we must ensure
reads are sychronized.

* Load cached request from cache.

To be done:
  - Tests (currently only test for the presence of the file).
  - No support for HTTPS (explicitly disabled).

* Tests for caching HTTP request from upstream.

* Select test class using test name prefix only.

* Tests for loading responses from cache.

* Implementation on enabled feature.

Cache is enabled by default.

* VCR feature of TestCase class with tests.

In this case, the cache should be disabled by default.

* Flush list when cache file is written on disk.

* When used with HTTPS resquests, `request.host` may be None

Use `Host` header in this case.

* Tests for caching HTTPS responses from upstream.

* Tests for answering HTTPS request from cache.

* Added newline in cache file test.

Co-authored-by: Abhinav Singh <[email protected]>
@codecov
Copy link

codecov bot commented Oct 4, 2020

Codecov Report

Merging #442 (8c2649b) into develop (88feecb) will increase coverage by 0.67%.
The diff coverage is 94.57%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #442      +/-   ##
===========================================
+ Coverage    78.58%   79.25%   +0.67%     
===========================================
  Files           83       85       +2     
  Lines         3124     3182      +58     
===========================================
+ Hits          2455     2522      +67     
+ Misses         669      660       -9     
Impacted Files Coverage Δ
proxy/dashboard/plugin.py 75.00% <ø> (+5.76%) ⬆️
proxy/http/proxy/server.py 78.14% <ø> (+0.33%) ⬆️
proxy/plugin/cache/cache_responses.py 91.66% <66.66%> (-8.34%) ⬇️
proxy/plugin/cache/base.py 90.74% <84.37%> (-2.37%) ⬇️
proxy/plugin/cache/store/disk.py 95.34% <95.00%> (-4.66%) ⬇️
proxy/__init__.py 100.00% <100.00%> (ø)
proxy/http/parser.py 99.39% <100.00%> (+5.01%) ⬆️
proxy/plugin/cache/store/base.py 100.00% <100.00%> (+20.00%) ⬆️
proxy/testing/__init__.py 100.00% <100.00%> (ø)
proxy/testing/base.py 100.00% <100.00%> (ø)
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 88feecb...8c2649b. Read the comment docs.

* Add request fingerprinting method.

1) Fix some tests due to change in default cache directory
2) Fix event propogation using multiprocessing manager

I/O error on closed resource is still an issue.  Doesn't result in
test error but a warning is thrown (tested on Python 3.8).

* Separate ReplayTestCase which also removes need of dynamic plugin enable/disable need

* Rename VCR to Replay

* Deprecate list.txt, use fingerprint of the request as cached file name.

1) Temporarily disable cache response plugin with tls interception. These
   are broken due to fingerprint mismatch.  For a https request, fingerprint
   must capture both CONNECT and then the sub-request state.

* Refactor tls_interception_enabled, add no cover tags on abc classes

* Add reference to issue#443
@abhinavsingh abhinavsingh marked this pull request as draft May 12, 2021 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants