diff --git a/transport/transport.go b/transport/transport.go index c41436e1..84a3269a 100644 --- a/transport/transport.go +++ b/transport/transport.go @@ -566,8 +566,12 @@ const ( percentByte = '%' ) -// grpcMessageEncode encodes the grpc-message field in the same -// manner as https://github.com/grpc/grpc-java/pull/1517. +// grpcMessageEncode is used to encode status code in header field +// "grpc-message". +// It checks to see if each individual byte in msg is an +// allowable byte, and then either percent encoding or passing it through. +// When percent encoding, the byte is converted into hexadecimal notation +// with a '%' prepended. func grpcMessageEncode(msg string) string { if msg == "" { return "" @@ -596,8 +600,7 @@ func grpcMessageEncodeUnchecked(msg string) string { return buf.String() } -// grpcMessageDecode decodes the grpc-message field in the same -// manner as https://github.com/grpc/grpc-java/pull/1517. +// grpcMessageDecode decodes the msg encoded by grpcMessageEncode. func grpcMessageDecode(msg string) string { if msg == "" { return "" diff --git a/transport/transport_test.go b/transport/transport_test.go index 6dd01d85..6e38fe17 100644 --- a/transport/transport_test.go +++ b/transport/transport_test.go @@ -732,7 +732,7 @@ func TestEncodingRequiredStatus(t *testing.T) { t.Fatalf("Failed to write the request: %v", err) } if _, err = ioutil.ReadAll(s); err != nil { - t.Fatal(err) + t.Fatalf("Read got err %v, want ", err) } ct.Close() server.stop() @@ -785,13 +785,13 @@ func TestGrpcMessageDecode(t *testing.T) { func testGrpcMessageEncode(t *testing.T, input string, expected string) { actual := grpcMessageEncode(input) if expected != actual { - t.Errorf("Expected %s from grpcMessageEncode, got %s", expected, actual) + t.Errorf("grpcMessageEncode(%v) = %v, want %v", input, actual, expected) } } func testGrpcMessageDecode(t *testing.T, input string, expected string) { actual := grpcMessageDecode(input) if expected != actual { - t.Errorf("Expected %s from grpcMessageDecode, got %s", expected, actual) + t.Errorf("grpcMessageDncode(%v) = %v, want %v", input, actual, expected) } }