You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
798 B
35 lines
798 B
4 years ago
|
package httputil
|
||
4 years ago
|
|
||
|
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.
|
||
4 years ago
|
// according rfc7231.
|
||
4 years ago
|
// contentType is assumed to be lowercase already.
|
||
|
func ContentSubtype(contentType string) string {
|
||
4 years ago
|
left := strings.Index(contentType, "/")
|
||
|
if left == -1 {
|
||
4 years ago
|
return ""
|
||
|
}
|
||
4 years ago
|
right := strings.Index(contentType, ";")
|
||
|
if right == -1 {
|
||
|
right = len(contentType)
|
||
4 years ago
|
}
|
||
4 years ago
|
if right < left {
|
||
4 years ago
|
return ""
|
||
|
}
|
||
4 years ago
|
return contentType[left+1 : right]
|
||
4 years ago
|
}
|