Skip to content

Remove case sensitivity of Etag header for use_etag - #61441

Merged
Ch3LL merged 2 commits into
saltstack:masterfrom
nicholasmhughes:fix-etag-case-sensitivity
Jan 20, 2022
Merged

Remove case sensitivity of Etag header for use_etag#61441
Ch3LL merged 2 commits into
saltstack:masterfrom
nicholasmhughes:fix-etag-case-sensitivity

Conversation

@nicholasmhughes

Copy link
Copy Markdown
Contributor

What does this PR do?

See issue.

What issues does this PR fix or reference?

Fixes: #61440

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

Yes

Please review Salt's Contributing Guide for best practices.

See GitHub's page on GPG signing for more information about signing commits with GPG.

@nicholasmhughes
nicholasmhughes requested a review from a team as a code owner January 11, 2022 01:29
@nicholasmhughes
nicholasmhughes requested review from waynew and removed request for a team January 11, 2022 01:29
Comment thread salt/fileclient.py
@nicholasmhughes

Copy link
Copy Markdown
Contributor Author

re-run full all

@waynew waynew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread tests/pytests/functional/states/test_file.py
@waynew

waynew commented Jan 11, 2022

Copy link
Copy Markdown
Contributor

re-run all

@damon-atkins

damon-atkins commented Jan 12, 2022

Copy link
Copy Markdown
Contributor

Hi @nicholasmhughes thanks for doing this. A better method would be to write the whole header to a different file instead of using a file specific for etag. There are many ways to determine if a file should be cached from a web server. Keeping the whole header in a filename.meta file allows not only etag to be used but other techniques, like if-not-modified-since using the date from save header which is in the same format as what the web server provided (instead of try to create it). Instead of use_etag just have http_cache. e.g.

Here is some sample code, loading meta data, back into a case insensitive data structure.

meta_file = '{0}.meta'.format(dest_file)
with salt.utils.files.fopen(meta_file, 'r', encoding='utf-8') as meta_fh:
   cache_headers = requests.structures.CaseInsensitiveDict(data=salt.utils.json.load(meta_fh))

Not sure why salt does not use the request library.

How are you handling failures/partial downloads?

@dwoz dwoz added the Phosphorus v3005.0 Release code name and version label Jan 20, 2022
@Ch3LL
Ch3LL merged commit 3292ee9 into saltstack:master Jan 20, 2022
@nicholasmhughes
nicholasmhughes deleted the fix-etag-case-sensitivity branch January 20, 2022 18:27
@nicholasmhughes

Copy link
Copy Markdown
Contributor Author

@damon-atkins , totally understand the broader metadata perspective. However, I'm not really in a spot to address that at this time.

Regarding handling failures/partial downloads, the code additions for use_etag aren't in the critical path for content download handling itself... just the decision on whether or not to download. If an etag file isn't there, is corrupted, or otherwise "partial", then it'll be treated as not matching and re-download the content.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Phosphorus v3005.0 Release code name and version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] use_etag expects case-sensitive header Etag

7 participants