-
Notifications
You must be signed in to change notification settings - Fork 933
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: Server return with Attachment #2648
Conversation
Signed-off-by: YarBor <yarbor.ww@gmail.com>
Signed-off-by: YarBor <yarbor.ww@gmail.com>
rewrite logic,Put the api into protocol/triple/triple_protocol layer used triple/triple_protocol/header.go's logic Signed-off-by: YarBor <yarbor.ww@gmail.com>
Signed-off-by: YarBor <yarbor.ww@gmail.com>
} | ||
|
||
// NewOutgoingContext sets headers entirely. If there are existing headers, they would be replaced. | ||
// It is used for passing headers to server-side. | ||
// It is like grpc.NewOutgoingContext. | ||
// Please refer to https://github.com/grpc/grpc-go/blob/master/Documentation/grpc-metadata.md#sending-metadata. | ||
func NewOutgoingContext(ctx context.Context, header http.Header) context.Context { | ||
return context.WithValue(ctx, headerOutgoingKey{}, header) | ||
func NewOutgoingContext(ctx context.Context, data interface{}) (context.Context, 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.
Why do we need to modify the args of this function?
- I think
http.Header
is clear and efficient enough for users to use.
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 will change it back.
} | ||
|
||
// AppendToOutgoingContext merges kv pairs from user and existing headers. | ||
// It is used for passing headers to server-side. | ||
// It is like grpc.AppendToOutgoingContext. | ||
// Please refer to https://github.com/grpc/grpc-go/blob/master/Documentation/grpc-metadata.md#sending-metadata. | ||
func AppendToOutgoingContext(ctx context.Context, kv ...string) context.Context { | ||
func AppendToOutgoingContext(ctx context.Context, kv ...string) (context.Context, 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 is the reason of returning 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.
I think this needs to be discussed. Should there be constraints on the attachment key? When transmitting and returning within the framework, the first letter of the attachment key will be changed to uppercase. On the receiving side, we cannot restore the original key.
func ExtractFromOutgoingContext(ctx context.Context) http.Header { | ||
headerRaw := ctx.Value(headerOutgoingKey{}) | ||
if headerRaw == nil { | ||
func ExtractFromOutgoingContext(ctx context.Context) map[string][]string { |
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.
ditto.
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 will change it back.
// Please refer to https://github.com/grpc/grpc-go/blob/master/Documentation/grpc-metadata.md#receiving-metadata-1. | ||
func FromIncomingContext(ctx context.Context) (http.Header, bool) { | ||
header, ok := ctx.Value(headerIncomingKey{}).(http.Header) | ||
func FromIncomingContext(ctx context.Context) (map[string][]string, bool) { |
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.
ditto.
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 will change it back.
@@ -181,3 +231,11 @@ func SendHeader(ctx context.Context, header http.Header) error { | |||
mergeHeaders(conn.RequestHeader(), header) | |||
return conn.Send(nil) | |||
} | |||
|
|||
func outGoingKeyCheck(key string) bool { |
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.
Where is this function used?
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.
ditto.
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 think it should be check.
client/client.go
Outdated
@@ -59,7 +59,8 @@ func (conn *Connection) call(ctx context.Context, reqs []interface{}, resp inter | |||
if err != nil { | |||
return nil, err | |||
} | |||
return conn.refOpts.invoker.Invoke(ctx, inv), nil | |||
res := conn.refOpts.invoker.Invoke(ctx, inv) |
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.
It seems there is no need to change statement style.
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.
Yes, the change here is a mistake. This was a change while testing, I will change it back to how it was.
protocol/triple/triple_invoker.go
Outdated
@@ -136,36 +143,50 @@ func (ti *TripleInvoker) Invoke(ctx context.Context, invocation protocol.Invocat | |||
return &result | |||
} | |||
|
|||
func mergeAttachmentToOutgoing(ctx context.Context, attachments map[string]interface{}) (context.Context, 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.
Since you extract attachments merge logic from parseInvocation
. Why do not extract entire logics about processing attachments?
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 think u are right.
Signed-off-by: YarBor <yarbor.ww@gmail.com>
Signed-off-by: YarBor <yarbor.ww@gmail.com>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2648 +/- ##
=======================================
Coverage 47.31% 47.31%
=======================================
Files 341 341
Lines 25165 25165
=======================================
Hits 11908 11908
Misses 12106 12106
Partials 1151 1151 ☔ View full report in Codecov by Sentry. |
…all 4 calling methods. Signed-off-by: YarBor <yarbor.ww@gmail.com>
Signed-off-by: YarBor <yarbor.ww@gmail.com>
Quality Gate passedIssues Measures |
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.
LGTM.
fix: Server return with Attachment (#2641)
client-side-call
server-side
new api applies to all 4 calling methods.