github.com/go-board/x-go@v0.1.2-0.20220610024734-db1323f6cb15/xnet/xhttp/xrequest/util.go (about) 1 package xrequest 2 3 import ( 4 "fmt" 5 "net/http" 6 "strings" 7 8 "github.com/go-board/x-go/xnet/xhttp" 9 ) 10 11 func errorBodyNotAllowed(method string) error { 12 return fmt.Errorf("method %s don't take any body", method) 13 } 14 15 func errorContentType(expected string, header http.Header) error { 16 contentType := header.Get(xhttp.HeaderContentType) 17 if expected == contentType || 18 strings.Contains(contentType, expected) { // for application/json; charset=utf-8 case 19 return nil 20 } 21 return fmt.Errorf("expected content-type is %s, but header %s", expected, contentType) 22 }