forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContentType.cs
More file actions
135 lines (95 loc) · 3.74 KB
/
Copy pathContentType.cs
File metadata and controls
135 lines (95 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using System;
using ServiceStack.ServiceHost;
namespace ServiceStack.Common.Web
{
public static class ContentType
{
public const string Utf8Suffix = "; charset=utf-8";
public const string HeaderContentType = "Content-Type";
public const string FormUrlEncoded = "application/x-www-form-urlencoded";
public const string MultiPartFormData = "multipart/form-data";
public const string Html = "text/html";
public const string JsonReport = "text/jsonreport";
public const string Xml = "application/xml";
public const string XmlText = "text/xml";
public const string Soap11 = " text/xml; charset=utf-8";
public const string Soap12 = " application/soap+xml";
public const string Json = "application/json";
public const string JsonText = "text/json";
public const string JavaScript = "application/javascript";
public const string Jsv = "application/jsv";
public const string JsvText = "text/jsv";
public const string Csv = "text/csv";
public const string Yaml = "application/yaml";
public const string YamlText = "text/yaml";
public const string PlainText = "text/plain";
public const string MarkdownText = "text/markdown";
public const string ProtoBuf = "application/x-protobuf";
public const string Binary = "application/octet-stream";
public static string GetRealContentType(string contentType)
{
return contentType == null
? null
: contentType.Split(';')[0].Trim();
}
public static Feature GetFeature(string contentType)
{
if (contentType == null)
return Feature.None;
var realContentType = GetRealContentType(contentType);
switch (realContentType)
{
case Json:
case JsonText:
return Feature.Json;
case Xml:
case XmlText:
return Feature.Xml;
case Html:
return Feature.Html;
case Jsv:
case JsvText:
return Feature.Jsv;
case Csv:
return Feature.Csv;
case Soap11:
return Feature.Soap11;
case Soap12:
return Feature.Soap12;
}
return Feature.None;
}
public static string GetContentFormat(EndpointType endpointType)
{
return endpointType.ToString().ToLower();
}
public static string GetContentFormat(string contentType)
{
if (contentType == null) return contentType;
var parts = contentType.Split('/');
return parts[parts.Length - 1];
}
public static string ToContentFormat(this string contentType)
{
return GetContentFormat(contentType);
}
public static string GetContentType(EndpointType endpointType)
{
switch (endpointType)
{
case EndpointType.Soap11:
case EndpointType.Soap12:
case EndpointType.Xml:
return Xml;
case EndpointType.Json:
return Json;
case EndpointType.Jsv:
return JsvText;
case EndpointType.ProtoBuf:
return ProtoBuf;
default:
return null;
}
}
}
}