mirror of
https://github.com/go-kratos/kratos.git
synced 2025-01-14 02:33:03 +02:00
fa54a1dd3a
* feat: Support custom status code conversion from HTTP and gRPC. Co-authored-by: Letian Yi <yiletian@webull.com>
35 lines
798 B
Go
35 lines
798 B
Go
package httputil
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
const (
|
|
baseContentType = "application"
|
|
)
|
|
|
|
// ContentType returns the content-type with base prefix.
|
|
func ContentType(subtype string) string {
|
|
return strings.Join([]string{baseContentType, subtype}, "/")
|
|
}
|
|
|
|
// ContentSubtype returns the content-subtype for the given content-type. The
|
|
// given content-type must be a valid content-type that starts with
|
|
// but no content-subtype will be returned.
|
|
// according rfc7231.
|
|
// contentType is assumed to be lowercase already.
|
|
func ContentSubtype(contentType string) string {
|
|
left := strings.Index(contentType, "/")
|
|
if left == -1 {
|
|
return ""
|
|
}
|
|
right := strings.Index(contentType, ";")
|
|
if right == -1 {
|
|
right = len(contentType)
|
|
}
|
|
if right < left {
|
|
return ""
|
|
}
|
|
return contentType[left+1 : right]
|
|
}
|