Skip to content
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

Fix HEAD requests for static content #4813

Merged
merged 4 commits into from
Oct 15, 2020
Merged

Conversation

bmerry
Copy link
Contributor

@bmerry bmerry commented Jun 10, 2020

What do these changes do?

It makes HEAD requests work correctly for static resources.

FileResponse directly injects the response into the socket with
sendfile() (if it can), which bypasses the checks in Response that
prevent any content being sent for HEAD requests and for 204 (No
Content) and 304 (Not Modified) responses. I've duplicated that logic
into FileResponse. I'm not sure if the status checks are actually
applicable (since StaticResource already has its own handling for Not
Modified) and I don't currently have any tests for them.

Are there changes in behavior for the user?

Bugfix only.

Related issue number

#4809

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • The format is <Name> <Surname>.
    • Please keep alphabetical order, the file is sorted by names.
  • Add a new news fragment into the CHANGES folder
    • name it <issue_id>.<type> for example (588.bugfix)
    • if you don't have an issue_id change it to the pr id after creating the pr
    • ensure type is one of the following:
      • .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.
    • Make sure to use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files."

FileResponse directly injects the response into the socket with
sendfile() (if it can), which bypasses the checks in Response that
prevent any content being sent for HEAD requests and for 204 (No
Content) and 304 (Not Modified) responses. I've duplicated that logic
into FileResponse. I'm not sure if the status checks are actually
applicable (since StaticResource already has its own handling for Not
Modified) and I don't currently have any tests for them.

Closes aio-libs#4809.
@bmerry bmerry requested a review from asvetlov as a code owner June 10, 2020 14:30
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Jun 10, 2020
@bmerry bmerry requested a review from webknjaz as a code owner June 10, 2020 14:30
@codecov-commenter
Copy link

codecov-commenter commented Jun 10, 2020

Codecov Report

Merging #4813 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #4813   +/-   ##
=======================================
  Coverage   97.60%   97.60%           
=======================================
  Files          43       43           
  Lines        8932     8934    +2     
  Branches     1406     1407    +1     
=======================================
+ Hits         8718     8720    +2     
  Misses         95       95           
  Partials      119      119           
Impacted Files Coverage Δ
aiohttp/web_fileresponse.py 97.84% <100.00%> (+0.02%) ⬆️

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 385b03e...98591ab. Read the comment docs.

bmerry and others added 2 commits June 10, 2020 16:39
StreamWriter.wait_closed doesn't exist on 3.6.
Copy link
Member

@asvetlov asvetlov left a comment

Choose a reason for hiding this comment

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

LGTM, makes sense.
Thanks for the fix!

@asvetlov asvetlov merged commit 81f1a2e into aio-libs:master Oct 15, 2020
@github-actions
Copy link
Contributor

💔 Backport was not successful

The PR was attempted backported to the following branches:

  • ❌ 3.7: Commit could not be cherrypicked due to conflicts

@bmerry bmerry deleted the fix-4809 branch October 15, 2020 14:00
asvetlov pushed a commit that referenced this pull request Oct 15, 2020
* Fix HEAD requests for static content

FileResponse directly injects the response into the socket with
sendfile() (if it can), which bypasses the checks in Response that
prevent any content being sent for HEAD requests and for 204 (No
Content) and 304 (Not Modified) responses. I've duplicated that logic
into FileResponse. I'm not sure if the status checks are actually
applicable (since StaticResource already has its own handling for Not
Modified) and I don't currently have any tests for them.

Closes #4809.
asvetlov pushed a commit that referenced this pull request Oct 16, 2020
* Fix HEAD requests for static content

FileResponse directly injects the response into the socket with
sendfile() (if it can), which bypasses the checks in Response that
prevent any content being sent for HEAD requests and for 204 (No
Content) and 304 (Not Modified) responses. I've duplicated that logic
into FileResponse. I'm not sure if the status checks are actually
applicable (since StaticResource already has its own handling for Not
Modified) and I don't currently have any tests for them.

Closes #4809.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot:chronographer:provided There is a change note present in this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants