From 5d7ad14de4c8ac9bbe0e4f0551934ac8faddbcf2 Mon Sep 17 00:00:00 2001 From: Menghan Li Date: Tue, 7 Jun 2016 17:45:14 -0700 Subject: [PATCH] Rename isGrpcContentType to validContentType --- transport/handler_server.go | 2 +- transport/http_util.go | 4 ++-- transport/http_util_test.go | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/transport/handler_server.go b/transport/handler_server.go index b8639676..00d3855f 100644 --- a/transport/handler_server.go +++ b/transport/handler_server.go @@ -65,7 +65,7 @@ func NewServerHandlerTransport(w http.ResponseWriter, r *http.Request) (ServerTr if r.Method != "POST" { return nil, errors.New("invalid gRPC request method") } - if !isGrpcContentType(r.Header.Get("Content-Type")) { + if !validContentType(r.Header.Get("Content-Type")) { return nil, errors.New("invalid gRPC request content-type") } if _, ok := w.(http.Flusher); !ok { diff --git a/transport/http_util.go b/transport/http_util.go index 6ae86b16..f2e23dce 100644 --- a/transport/http_util.go +++ b/transport/http_util.go @@ -144,7 +144,7 @@ func (d *decodeState) setErr(err error) { } } -func isGrpcContentType(t string) bool { +func validContentType(t string) bool { e := "application/grpc" if !strings.HasPrefix(t, e) { return false @@ -160,7 +160,7 @@ func isGrpcContentType(t string) bool { func (d *decodeState) processHeaderField(f hpack.HeaderField) { switch f.Name { case "content-type": - if !isGrpcContentType(f.Value) { + if !validContentType(f.Value) { d.setErr(StreamErrorf(codes.FailedPrecondition, "transport: received the unexpected content-type %q", f.Value)) return } diff --git a/transport/http_util_test.go b/transport/http_util_test.go index eb3b2c06..279acbc5 100644 --- a/transport/http_util_test.go +++ b/transport/http_util_test.go @@ -86,7 +86,7 @@ func TestTimeoutDecode(t *testing.T) { } } -func TestIsGrpcContentType(t *testing.T) { +func TestValidContentType(t *testing.T) { tests := []struct { h string want bool @@ -101,9 +101,9 @@ func TestIsGrpcContentType(t *testing.T) { {"application/grp", false}, } for _, tt := range tests { - got := isGrpcContentType(tt.h) + got := validContentType(tt.h) if got != tt.want { - t.Errorf("isGrpcContentType(%q) = %v; want %v", tt.h, got, tt.want) + t.Errorf("validContentType(%q) = %v; want %v", tt.h, got, tt.want) } } }