-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathMetadataFeature.cs
More file actions
91 lines (73 loc) · 3.13 KB
/
MetadataFeature.cs
File metadata and controls
91 lines (73 loc) · 3.13 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
using System.Web;
using ServiceStack.WebHost.Endpoints;
using ServiceStack.WebHost.Endpoints.Metadata;
namespace ServiceStack
{
public class MetadataFeature : IPlugin
{
public void Register(IAppHost appHost)
{
appHost.CatchAllHandlers.Add(ProcessRequest);
}
public IHttpHandler ProcessRequest(string httpMethod, string pathInfo, string filePath)
{
var pathParts = pathInfo.TrimStart('/').Split('/');
if (pathParts.Length == 0) return null;
return GetHandlerForPathParts(pathParts);
}
private IHttpHandler GetHandlerForPathParts(string[] pathParts)
{
var pathController = string.Intern(pathParts[0].ToLower());
if (pathParts.Length == 1)
{
if (pathController == "metadata")
return new IndexMetadataHandler();
return null;
}
var pathAction = string.Intern(pathParts[1].ToLower());
if (pathAction == "wsdl")
{
if (pathController == "soap11")
return new Soap11WsdlMetadataHandler();
if (pathController == "soap12")
return new Soap12WsdlMetadataHandler();
}
if (pathAction != "metadata") return null;
switch (pathController)
{
case "json":
return new JsonMetadataHandler();
case "xml":
return new XmlMetadataHandler();
case "jsv":
return new JsvMetadataHandler();
case "soap11":
return new Soap11MetadataHandler();
case "soap12":
return new Soap12MetadataHandler();
case "types":
if (EndpointHost.Config == null
|| EndpointHost.Config.MetadataTypesConfig == null)
return null;
if (EndpointHost.Config.MetadataTypesConfig.BaseUrl == null)
EndpointHost.Config.MetadataTypesConfig.BaseUrl = ServiceStackHttpHandlerFactory.GetBaseUrl();
return new MetadataTypesHandler { Config = EndpointHost.AppHost.Config.MetadataTypesConfig };
case "operations":
return new ActionHandler((httpReq, httpRes) =>
EndpointHost.Config.HasAccessToMetadata(httpReq, httpRes)
? EndpointHost.Metadata.GetOperationDtos()
: null, "Operations");
default:
string contentType;
if (EndpointHost.ContentTypeFilter
.ContentTypeFormats.TryGetValue(pathController, out contentType))
{
var format = Common.Web.ContentType.GetContentFormat(contentType);
return new CustomMetadataHandler(contentType, format);
}
break;
}
return null;
}
}
}