Fix HEAD method in resources.GetRemote

Fixes #10604
This commit is contained in:
Bjørn Erik Pedersen
2023-01-16 11:05:28 +01:00
parent b5d485060f
commit f13531e608
4 changed files with 135 additions and 43 deletions

View File

@@ -117,7 +117,7 @@ func FromContent(types Types, extensionHints []string, content []byte) Type {
// FromStringAndExt creates a Type from a MIME string and a given extension.
func FromStringAndExt(t, ext string) (Type, error) {
tp, err := fromString(t)
tp, err := FromString(t)
if err != nil {
return tp, err
}
@@ -129,7 +129,7 @@ func FromStringAndExt(t, ext string) (Type, error) {
// FromString creates a new Type given a type string on the form MainType/SubType and
// an optional suffix, e.g. "text/html" or "text/html+html".
func fromString(t string) (Type, error) {
func FromString(t string) (Type, error) {
t = strings.ToLower(t)
parts := strings.Split(t, "/")
if len(parts) != 2 {
@@ -470,7 +470,7 @@ func DecodeTypes(mms ...map[string]any) (Types, error) {
mediaType, found := mmm[k]
if !found {
var err error
mediaType, err = fromString(k)
mediaType, err = FromString(k)
if err != nil {
return m, err
}

View File

@@ -132,22 +132,22 @@ func TestGetFirstBySuffix(t *testing.T) {
func TestFromTypeString(t *testing.T) {
c := qt.New(t)
f, err := fromString("text/html")
f, err := FromString("text/html")
c.Assert(err, qt.IsNil)
c.Assert(f.Type(), qt.Equals, HTMLType.Type())
f, err = fromString("application/custom")
f, err = FromString("application/custom")
c.Assert(err, qt.IsNil)
c.Assert(f, qt.Equals, Type{MainType: "application", SubType: "custom", mimeSuffix: ""})
f, err = fromString("application/custom+sfx")
f, err = FromString("application/custom+sfx")
c.Assert(err, qt.IsNil)
c.Assert(f, qt.Equals, Type{MainType: "application", SubType: "custom", mimeSuffix: "sfx"})
_, err = fromString("noslash")
_, err = FromString("noslash")
c.Assert(err, qt.Not(qt.IsNil))
f, err = fromString("text/xml; charset=utf-8")
f, err = FromString("text/xml; charset=utf-8")
c.Assert(err, qt.IsNil)
c.Assert(f, qt.Equals, Type{MainType: "text", SubType: "xml", mimeSuffix: ""})