Rename isGrpcContentType to validContentType
This commit is contained in:
Родитель
7ef3c44f78
Коммит
5d7ad14de4
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче