Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions protocol/triple/triple_protocol/handler_compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package triple_protocol
import (
"context"
"errors"
"fmt"
"net/http"
)

Expand Down Expand Up @@ -88,7 +87,7 @@ func (t *tripleCompatInterceptor) compatUnaryServerInterceptor(ctx context.Conte
case []string:
trailer[key] = valRaw
default:
panic(fmt.Sprintf("unsupported attachment value type %T", valRaw))
logger.Warnf("[Triple][Handler] procedure %s skips unsupported trailer attachment %s with value type %T", t.procedure, key, valRaw)
}
}
resp.trailer = trailer
Expand Down
32 changes: 32 additions & 0 deletions protocol/triple/triple_protocol/handler_compat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package triple_protocol

import (
"context"
"testing"
)

Expand All @@ -26,6 +27,11 @@ import (
"github.com/dubbogo/grpc-go/status"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

import (
"dubbo.apache.org/dubbo-go/v3/protocol/result"
)

func TestCompatError(t *testing.T) {
Expand All @@ -36,3 +42,29 @@ func TestCompatError(t *testing.T) {
assert.Equal(t, "user defined", triErr.Message())
assert.Len(t, triErr.Details(), 1)
}

func TestCompatUnaryServerInterceptorSkipsUnsupportedAttachmentValue(t *testing.T) {
t.Parallel()

interceptor := &tripleCompatInterceptor{procedure: "test.Service/Method"}
respRaw, err := interceptor.compatUnaryServerInterceptor(
context.Background(),
"request",
nil,
func(context.Context, any) (any, error) {
rpcResult := &result.RPCResult{Rest: "response"}
rpcResult.SetAttachments(map[string]any{
"String-Value": "ok",
"List-Value": []string{"a", "b"},
"Bool-Value": true,
})
return rpcResult, nil
},
)

require.NoError(t, err)
resp := respRaw.(*Response)
assert.Equal(t, []string{"ok"}, resp.Trailer().Values("String-Value"))
assert.Equal(t, []string{"a", "b"}, resp.Trailer().Values("List-Value"))
assert.Empty(t, resp.Trailer().Values("Bool-Value"))
}
Loading