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

Add support for callback header #8

Merged
merged 2 commits into from
Mar 21, 2024
Merged

Conversation

bergundy
Copy link
Contributor

Exposed callback headers as defined in this recent change to the API:

nexus-rpc/api#4

nexus/api.go Outdated
// Nexus headers can only have single values, ignore multiple values.
header[strings.ToLower(k[8:])] = v[0]
header[lowerK[8:]] = v[0]

Choose a reason for hiding this comment

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

nit: I think putting this in a stripPrefix helper and then using len(prefix) here would be cleaner.

nexus/api.go Outdated
for k, v := range httpHeader {
lowerK := strings.ToLower(k)
if strings.HasPrefix(lowerK, "nexus-callback-") {
// Nexus headers can only have single values, ignore multiple values.

Choose a reason for hiding this comment

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

Just want to make sure, is this in the spec? It seems like a limitation people should be aware of. Also, why do we need this limitation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For compatibility with gRPC, Kafka, and Temporal headers.
This is the lowest common denominator.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought I put it in the spec. I'll update, thanks.

nexus/api.go Outdated
lowerK := strings.ToLower(k)
if strings.HasPrefix(lowerK, "nexus-callback-") {
// Nexus headers can only have single values, ignore multiple values.
header[lowerK[15:]] = v[0]

Choose a reason for hiding this comment

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

nit: I know headers should be case insensitive, but it seems weird that we're forcing them to be lowercase now. Could we just do header[k[15:]] = v[0] instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, but it really doesn't matter.

@@ -259,6 +260,9 @@ type ExecuteOperationOptions struct {
// Even though Client.ExecuteOperation waits for operation completion, some applications may want to set this
// callback as a fallback mechanism.
CallbackURL string
// Optional header fields set by a client that are required to be attached to the callback request when an
// asynchronous operation completes.
CallbackHeader Header

Choose a reason for hiding this comment

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

If there can only be one value per key here, consider just using a map.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Header has a case insensitive getter, it's convenient.

@bergundy bergundy merged commit 31b136e into nexus-rpc:main Mar 21, 2024
3 checks passed
@bergundy bergundy deleted the callback-header branch March 21, 2024 04:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants