forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperationControl.cs
More file actions
103 lines (90 loc) · 2.89 KB
/
OperationControl.cs
File metadata and controls
103 lines (90 loc) · 2.89 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
using System.Web;
using System.Web.UI;
using ServiceStack.Templates;
using ServiceStack.Text;
using ServiceStack.Web;
namespace ServiceStack.Metadata
{
public class OperationControl
{
public ServiceEndpointsMetadataConfig MetadataConfig { get; set; }
public Format Format
{
set
{
this.ContentType = ServiceStack.ContentFormat.ToContentType(value);
this.ContentFormat = ServiceStack.ContentFormat.GetContentFormat(value);
}
}
public IRequest HttpRequest { get; set; }
public string ContentType { get; set; }
public string ContentFormat { get; set; }
public string Title { get; set; }
public string OperationName { get; set; }
public string HostName { get; set; }
public string RequestMessage { get; set; }
public string ResponseMessage { get; set; }
public string MetadataHtml { get; set; }
public virtual string RequestUri
{
get
{
var endpointConfig = MetadataConfig.GetEndpointConfig(ContentType);
var endpontPath = ResponseMessage != null
? endpointConfig.SyncReplyUri : endpointConfig.AsyncOneWayUri;
return string.Format("{0}/{1}", endpontPath, OperationName);
}
}
public virtual void Render(HtmlTextWriter output)
{
string baseUrl = HttpRequest.ResolveAbsoluteUrl("~/");
var renderedTemplate = HtmlTemplates.Format(HtmlTemplates.GetOperationControlTemplate(),
Title,
baseUrl.CombineWith(MetadataConfig.DefaultMetadataUri),
ContentFormat.ToUpper(),
OperationName,
HttpRequestTemplate,
ResponseTemplate,
MetadataHtml);
output.Write(renderedTemplate);
}
public virtual string HttpRequestTemplate
{
get
{
return string.Format(
@"POST {0} HTTP/1.1
Host: {1}
Content-Type: {2}
Content-Length: <span class=""value"">length</span>
{3}", RequestUri, HostName, ContentType, HttpUtility.HtmlEncode(RequestMessage));
}
}
public virtual string ResponseTemplate
{
get
{
var httpResponse = this.HttpResponseTemplate;
return string.IsNullOrEmpty(httpResponse) ? null : string.Format(@"
<div class=""response"">
<pre>
{0}
</pre>
</div>
", httpResponse);
}
}
public virtual string HttpResponseTemplate
{
get
{
if (string.IsNullOrEmpty(ResponseMessage)) return null;
return string.Format(
@"HTTP/1.1 200 OK
Content-Type: {0}
Content-Length: length
{1}", ContentType, HttpUtility.HtmlEncode(ResponseMessage));
}
}
}
}