Skip to content

[async-await] Support for sending response headers via context #1262

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

Merged

Conversation

simonjbeaumont
Copy link
Collaborator

The adopter may wish to set the response headers (aka "initial metadata") from their user handler. Until now this was not possible, even in the existing non–async-await API, and it was only possible for an adopter to set the trailers.

This introduces a new mutable property to the context passed to the user handler that allows them to set the headers that should be sent back to the client before the first response message.

  • let GRPCAsyncServerCallContext.headers has been renamed to requestHeaders to disambiguate from newly introduced property.
  • var GRPCAsyncServerCallContext.trailers has been renamed to responseTrailers to better align with newly introduced property.
  • var GRPCAsyncServerCallContext.responseHeaders has been introduced.

Copy link
Collaborator Author

@simonjbeaumont simonjbeaumont left a comment

Choose a reason for hiding this comment

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

@glbrntt I guess it's obvious but this changes the semantics as seen from the client. It used to be they would get an instant "reply" with the initial metadata. Now they don't get anything until the first response which means that, in the event that the user handler doesn't return anything before the deadline, the client will timeout.

Just wanted to call this out and confirm we expect, and are happy with, these semantics?

Copy link
Collaborator

@glbrntt glbrntt left a comment

Choose a reason for hiding this comment

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

@glbrntt I guess it's obvious but this changes the semantics as seen from the client. It used to be they would get an instant "reply" with the initial metadata. Now they don't get anything until the first response which means that, in the event that the user handler doesn't return anything before the deadline, the client will timeout.

Just wanted to call this out and confirm we expect, and are happy with, these semantics?

I think so, yes. This is what the C# and Go implementations do. Go also has a function to send headers directly.

As a follow up, I think we should add a note to initial metadata on the client to explain that it's not always the case that we'll receive them right away.

@glbrntt glbrntt added the 🆕 semver/minor Adds new public API. label Sep 13, 2021
Signed-off-by: Si Beaumont <[email protected]>
Copy link
Collaborator

@glbrntt glbrntt left a comment

Choose a reason for hiding this comment

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

LGTM, thanks Si!

@glbrntt glbrntt merged commit 6c5c289 into grpc:async-await Sep 13, 2021
glbrntt pushed a commit to glbrntt/grpc-swift that referenced this pull request Sep 16, 2021
…1262)

The adopter may wish to set the response headers (aka "initial metadata") from their user handler. Until now this was not possible, even in the existing non–async-await API, and it was only possible for an adopter to set the trailers.

This introduces a new mutable property to the context passed to the user handler that allows them to set the headers that should be sent back to the client before the first response message.

* `let GRPCAsyncServerCallContext.headers` has been renamed to `requestHeaders` to disambiguate from newly introduced property.
* `var GRPCAsyncServerCallContext.trailers` has been renamed to `responseTrailers` to better align with newly introduced property.
* `var GRPCAsyncServerCallContext.responseHeaders` has been introduced.
glbrntt pushed a commit to glbrntt/grpc-swift that referenced this pull request Sep 16, 2021
…1262)

The adopter may wish to set the response headers (aka "initial metadata") from their user handler. Until now this was not possible, even in the existing non–async-await API, and it was only possible for an adopter to set the trailers.

This introduces a new mutable property to the context passed to the user handler that allows them to set the headers that should be sent back to the client before the first response message.

* `let GRPCAsyncServerCallContext.headers` has been renamed to `requestHeaders` to disambiguate from newly introduced property.
* `var GRPCAsyncServerCallContext.trailers` has been renamed to `responseTrailers` to better align with newly introduced property.
* `var GRPCAsyncServerCallContext.responseHeaders` has been introduced.
glbrntt pushed a commit that referenced this pull request Sep 16, 2021
The adopter may wish to set the response headers (aka "initial metadata") from their user handler. Until now this was not possible, even in the existing non–async-await API, and it was only possible for an adopter to set the trailers.

This introduces a new mutable property to the context passed to the user handler that allows them to set the headers that should be sent back to the client before the first response message.

* `let GRPCAsyncServerCallContext.headers` has been renamed to `requestHeaders` to disambiguate from newly introduced property.
* `var GRPCAsyncServerCallContext.trailers` has been renamed to `responseTrailers` to better align with newly introduced property.
* `var GRPCAsyncServerCallContext.responseHeaders` has been introduced.
glbrntt pushed a commit that referenced this pull request Nov 26, 2021
The adopter may wish to set the response headers (aka "initial metadata") from their user handler. Until now this was not possible, even in the existing non–async-await API, and it was only possible for an adopter to set the trailers.

This introduces a new mutable property to the context passed to the user handler that allows them to set the headers that should be sent back to the client before the first response message.

* `let GRPCAsyncServerCallContext.headers` has been renamed to `requestHeaders` to disambiguate from newly introduced property.
* `var GRPCAsyncServerCallContext.trailers` has been renamed to `responseTrailers` to better align with newly introduced property.
* `var GRPCAsyncServerCallContext.responseHeaders` has been introduced.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants