Skip to content

Commit e38460d

Browse files
committed
Call new APIs moved down to MimeTypes in SS.Text
1 parent 60cdca1 commit e38460d

1 file changed

Lines changed: 4 additions & 83 deletions

File tree

src/ServiceStack.Client/ContentFormat.cs

Lines changed: 4 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -77,91 +77,12 @@ public static string NormalizeContentType(string contentType)
7777
: realContentType;
7878
}
7979

80-
//lowercases and trims left part of content-type prior ';'
81-
public static string GetRealContentType(string contentType)
82-
{
83-
if (contentType == null)
84-
return null;
85-
86-
int start = -1, end = -1;
87-
88-
for(int i=0; i < contentType.Length; i++)
89-
{
90-
if (!char.IsWhiteSpace(contentType[i]))
91-
{
92-
if (contentType[i] == ';')
93-
break;
94-
if (start == -1)
95-
{
96-
start = i;
97-
}
98-
end = i;
99-
}
100-
}
101-
102-
return start != -1
103-
? contentType.Substring(start, end - start + 1).ToLowerInvariant()
104-
: null;
105-
}
106-
107-
//Compares two string from start to ';' char, case-insensitive,
108-
//ignoring (trimming) spaces at start and end
109-
public static bool MatchesContentType(this string contentType, string matchesContentType)
110-
{
111-
if (contentType == null || matchesContentType == null)
112-
return false;
113-
114-
int start = -1, matchStart = -1, matchEnd = -1;
115-
116-
for (var i=0; i < contentType.Length; i++)
117-
{
118-
if (char.IsWhiteSpace(contentType[i]))
119-
continue;
120-
start = i;
121-
break;
122-
}
123-
124-
for (var i=0; i < matchesContentType.Length; i++)
125-
{
126-
if (char.IsWhiteSpace(matchesContentType[i]))
127-
continue;
128-
if (matchesContentType[i] == ';')
129-
break;
130-
if (matchStart == -1)
131-
matchStart = i;
132-
matchEnd = i;
133-
}
134-
135-
return start != -1 && matchStart != -1 && matchEnd != -1
136-
&& string.Compare(contentType, start,
137-
matchesContentType, matchStart, matchEnd - matchStart + 1,
138-
StringComparison.OrdinalIgnoreCase) == 0;
139-
}
140-
141-
public static bool IsBinary(this string contentType)
142-
{
143-
var realContentType = GetRealContentType(contentType);
144-
switch (realContentType)
145-
{
146-
case MimeTypes.ProtoBuf:
147-
case MimeTypes.MsgPack:
148-
case MimeTypes.Binary:
149-
case MimeTypes.Bson:
150-
case MimeTypes.Wire:
151-
return true;
152-
}
80+
public static string GetRealContentType(string contentType) => MimeTypes.GetRealContentType(contentType);
15381

154-
var primaryType = realContentType.LeftPart('/');
155-
switch (primaryType)
156-
{
157-
case "image":
158-
case "audio":
159-
case "video":
160-
return true;
161-
}
82+
public static bool MatchesContentType(this string contentType, string matchesContentType) =>
83+
MimeTypes.MatchesContentType(contentType, matchesContentType);
16284

163-
return false;
164-
}
85+
public static bool IsBinary(this string contentType) => MimeTypes.IsBinary(contentType);
16586

16687
public static Feature ToFeature(this string contentType)
16788
{

0 commit comments

Comments
 (0)