-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
add append_version feature into StaticResource url resolver #2158
Conversation
Please mention new parameter and behavior in docs |
I have added documentation for |
The PR only generates new version tag by Should it return redirection response on version mismatch? Should we move It might simplify the usage: just add static files handler with parameter set ( |
Should it return redirection response on version mismatch? Should we move append_version parameter to constructor? |
Codecov Report
@@ Coverage Diff @@
## master #2158 +/- ##
==========================================
+ Coverage 97.09% 97.11% +0.02%
==========================================
Files 39 39
Lines 7783 7878 +95
Branches 1357 1366 +9
==========================================
+ Hits 7557 7651 +94
Misses 101 101
- Partials 125 126 +1
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, let's don't redirect but add append_version
to router.add_static
aiohttp/web_urldispatcher.py
Outdated
# with_query remove previous query options | ||
url = self.url_for(filename=filename, append_version=append_version) | ||
if query is not None: | ||
return str(url.with_query(query)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be update_query
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
aiohttp/web_urldispatcher.py
Outdated
return url | ||
return url | ||
|
||
def get_file_hash(self, byte_array): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add _
prefix to method name: it is not a part of public API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
aiohttp/web_urldispatcher.py
Outdated
return url | ||
except Exception as error: | ||
# perm error or other kind! | ||
# TODO log error here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if we should catch the exception.
url is useless: next GET will raise an error.
Moreover next open
call might fail too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
aiohttp/web_urldispatcher.py
Outdated
filepath = self._directory.joinpath(filename).resolve() | ||
if not self._follow_symlinks: | ||
filepath.relative_to(self._directory) | ||
except (ValueError, FileNotFoundError) as error: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What case could raise ValueError
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know, this is copied code from _handle
method, anyway i remove it
… method docs and tests is updated to reflect changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document append_version
parameter for add_static
in web_reference.rst
too
aiohttp/web_urldispatcher.py
Outdated
# with_query remove previous query options | ||
url = self.url_for(filename=filename, append_version=append_version) | ||
if query is not None: | ||
return str(url.update_query(query)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test for this case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
url = URL(url) | ||
if append_version is True: | ||
try: | ||
if filename.startswith('/'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test if filename
doesn't start with /
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
if filename.startswith('/'): | ||
filename = filename[1:] | ||
filepath = self._directory.joinpath(filename).resolve() | ||
if not self._follow_symlinks: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test for _follow_symlink
needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Thanks! |
Are there changes in behavior for the user?
Fully backward compatible feature (has no impact on exists code)
Related issue number
Please goto #2157 for description and discussion
Checklist
CONTRIBUTORS.txt
changes
folder<issue_id>.<type>
for example (588.bug)issue_id
change it to the pr id after creating the pr.feature
: Signifying a new feature..bugfix
: Signifying a bug fix..doc
: Signifying a documentation improvement..removal
: Signifying a deprecation or removal of public API..misc
: A ticket has been closed, but it is not of interest to users.