Rename isGrpcContentType to validContentType

This commit is contained in:
Menghan Li
2016-06-07 17:45:14 -07:00
parent 7ef3c44f78
commit 5d7ad14de4
3 changed files with 6 additions and 6 deletions

View File

@ -65,7 +65,7 @@ func NewServerHandlerTransport(w http.ResponseWriter, r *http.Request) (ServerTr
if r.Method != "POST" { if r.Method != "POST" {
return nil, errors.New("invalid gRPC request method") 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") return nil, errors.New("invalid gRPC request content-type")
} }
if _, ok := w.(http.Flusher); !ok { if _, ok := w.(http.Flusher); !ok {

View File

@ -144,7 +144,7 @@ func (d *decodeState) setErr(err error) {
} }
} }
func isGrpcContentType(t string) bool { func validContentType(t string) bool {
e := "application/grpc" e := "application/grpc"
if !strings.HasPrefix(t, e) { if !strings.HasPrefix(t, e) {
return false return false
@ -160,7 +160,7 @@ func isGrpcContentType(t string) bool {
func (d *decodeState) processHeaderField(f hpack.HeaderField) { func (d *decodeState) processHeaderField(f hpack.HeaderField) {
switch f.Name { switch f.Name {
case "content-type": 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)) d.setErr(StreamErrorf(codes.FailedPrecondition, "transport: received the unexpected content-type %q", f.Value))
return return
} }

View File

@ -86,7 +86,7 @@ func TestTimeoutDecode(t *testing.T) {
} }
} }
func TestIsGrpcContentType(t *testing.T) { func TestValidContentType(t *testing.T) {
tests := []struct { tests := []struct {
h string h string
want bool want bool
@ -101,9 +101,9 @@ func TestIsGrpcContentType(t *testing.T) {
{"application/grp", false}, {"application/grp", false},
} }
for _, tt := range tests { for _, tt := range tests {
got := isGrpcContentType(tt.h) got := validContentType(tt.h)
if got != tt.want { 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)
} }
} }
} }