|
|
|
@ -40,15 +40,22 @@ func (tr *Transport) ReplyHeader() transport.Header { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type mockHeader struct { |
|
|
|
|
m map[string]string |
|
|
|
|
m map[string][]string |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (m *mockHeader) Get(key string) string { |
|
|
|
|
return m.m[key] |
|
|
|
|
if m.m[key] == nil { |
|
|
|
|
return "" |
|
|
|
|
} |
|
|
|
|
return m.m[key][0] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (m *mockHeader) Set(key, value string) { |
|
|
|
|
m.m[key] = value |
|
|
|
|
m.m[key] = []string{value} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (m *mockHeader) Append(key string, value ...string) { |
|
|
|
|
m.m[key] = append(m.m[key], value...) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (m *mockHeader) Keys() []string { |
|
|
|
@ -185,28 +192,28 @@ func TestHeaderFunc(t *testing.T) { |
|
|
|
|
name: "/hello.Update/world", |
|
|
|
|
ctx: transport.NewServerContext(context.Background(), &Transport{ |
|
|
|
|
operation: "/hello.Update/world", |
|
|
|
|
headers: &mockHeader{map[string]string{"X-Test": "test"}}, |
|
|
|
|
headers: &mockHeader{map[string][]string{"X-Test": {"test"}}}, |
|
|
|
|
}), |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: "/hi.Create/world", |
|
|
|
|
ctx: transport.NewServerContext(context.Background(), &Transport{ |
|
|
|
|
operation: "/hi.Create/world", |
|
|
|
|
headers: &mockHeader{map[string]string{"X-Test": "test2", "go-kratos": "kratos"}}, |
|
|
|
|
headers: &mockHeader{map[string][]string{"X-Test": {"test2"}, "go-kratos": {"kratos"}}}, |
|
|
|
|
}), |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: "/test.Name/1234", |
|
|
|
|
ctx: transport.NewServerContext(context.Background(), &Transport{ |
|
|
|
|
operation: "/test.Name/1234", |
|
|
|
|
headers: &mockHeader{map[string]string{"X-Test": "test3"}}, |
|
|
|
|
headers: &mockHeader{map[string][]string{"X-Test": {"test3"}}}, |
|
|
|
|
}), |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: "/go-kratos.dev/kratos", |
|
|
|
|
ctx: transport.NewServerContext(context.Background(), &Transport{ |
|
|
|
|
operation: "/go-kratos.dev/kratos", |
|
|
|
|
headers: &mockHeader{map[string]string{"X-Test": "test"}}, |
|
|
|
|
headers: &mockHeader{map[string][]string{"X-Test": {"test"}}}, |
|
|
|
|
}), |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|