Skip to content

Prepare response headers prior to running prepare signal#4263

Closed
Qix- wants to merge 1 commit intoaio-libs:masterfrom
Qix-:header-prep-before-hook
Closed

Prepare response headers prior to running prepare signal#4263
Qix- wants to merge 1 commit intoaio-libs:masterfrom
Qix-:header-prep-before-hook

Conversation

@Qix-
Copy link
Copy Markdown
Contributor

@Qix- Qix- commented Oct 23, 2019

What do these changes do?

When a response is to be sent, this prepares the headers prior to running the prepare hook instead of after.

Are there changes in behavior for the user?

Any uses of the response prepare signal that assumed the headers are replaced after their signal handlers will now need to take this change into account.

Related issue number

Closes #1958.

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."

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Oct 23, 2019
@Qix-
Copy link
Copy Markdown
Contributor Author

Qix- commented Oct 23, 2019

Compliments on the testing and CI setup for this repository by the way, quite exemplary work done here. It was a pleasure working with this codebase given that I've never touched it before. Quite rare nowadays.

return writer

async def _prepare_headers(
self, request: 'BaseRequest', writer: AbstractStreamWriter
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should it accept a writer argument given that the same thing is effectively available via self._payload_writer anyway?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I can sure change it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Makes sense. request is available as self._req also.

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.

The issue is self._payload_writer and self._req are Optional[...] so _prepare_headers and _write_headers would need to guard against them being None to pacify mypy. Should they raise errors if that happens? Passing the non-Optional values might be preferable.

headers[hdrs.CONNECTION] = 'close'

async def _write_headers(
self, request: 'BaseRequest', writer: AbstractStreamWriter
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(same concern as above)

@webknjaz
Copy link
Copy Markdown
Member

@Qix- thanks for the PR! I've left a few comments and defer the rest of the review to @asvetlov.

Copy link
Copy Markdown
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.

Looks very good!
Please address two very minor comments.

return writer

async def _prepare_headers(
self, request: 'BaseRequest', writer: AbstractStreamWriter
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Makes sense. request is available as self._req also.

@asvetlov
Copy link
Copy Markdown
Member

@Qix- ping

@kwuite
Copy link
Copy Markdown

kwuite commented May 5, 2020

Will this get merged anytime soon?

@Qix-
Copy link
Copy Markdown
Contributor Author

Qix- commented May 5, 2020

Hi - I don't use this library anymore as I left the team that did. Someone else is free to pick it up if they'd like to.

@asvetlov
Copy link
Copy Markdown
Member

Done by #5064

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.

Possibility to disable Server header

5 participants