forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasicRequest.cs
More file actions
162 lines (123 loc) · 5.04 KB
/
Copy pathBasicRequest.cs
File metadata and controls
162 lines (123 loc) · 5.04 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Net;
using ServiceStack.Configuration;
using ServiceStack.Messaging;
using ServiceStack.Text;
using ServiceStack.Web;
namespace ServiceStack.Host
{
public class BasicRequest : IRequest
{
public object Dto { get; set; }
public IMessage Message { get; set; }
public object OriginalRequest { get; private set; }
public IResponse Response { get; set; }
private IResolver resolver;
public IResolver Resolver
{
get { return resolver ?? Service.GlobalResolver; }
set { resolver = value; }
}
public BasicRequest(object requestDto,
RequestAttributes requestAttributes = RequestAttributes.LocalSubnet | RequestAttributes.MessageQueue)
: this(MessageFactory.Create(requestDto), requestAttributes) {}
public BasicRequest(IMessage message = null,
RequestAttributes requestAttributes = RequestAttributes.LocalSubnet | RequestAttributes.MessageQueue)
{
Message = message ?? new Message();
ContentType = this.ResponseContentType = MimeTypes.Json;
this.Headers = PclExportClient.Instance.NewNameValueCollection();
if (Message.Body != null)
{
PathInfo = "/json/oneway/" + OperationName;
RawUrl = AbsoluteUri = "mq://" + PathInfo;
Headers = new NameValueCollectionWrapper(Message.ToHeaders().ToNameValueCollection());
}
this.IsLocal = true;
Response = new BasicResponse(this);
this.RequestAttributes = requestAttributes;
this.Verb = HttpMethods.Post;
this.Cookies = new Dictionary<string, Cookie>();
this.Items = new Dictionary<string, object>();
this.QueryString = PclExportClient.Instance.NewNameValueCollection();
this.FormData = PclExportClient.Instance.NewNameValueCollection();
this.Files = TypeConstants<IHttpFile>.EmptyArray;
}
private string operationName;
public string OperationName
{
get { return operationName ?? (operationName = Message.Body != null ? Message.Body.GetType().GetOperationName() : null); }
set { operationName = value; }
}
public T TryResolve<T>()
{
return Resolver.TryResolve<T>();
}
public string UserHostAddress { get; set; }
public string GetHeader(string headerName)
{
var headerValue = Headers[headerName];
return headerValue;
}
public Dictionary<string, object> Items { get; set; }
public string UserAgent { get; private set; }
public IDictionary<string, Cookie> Cookies { get; set; }
public string Verb { get; set; }
public RequestAttributes RequestAttributes { get; set; }
private IRequestPreferences requestPreferences;
public IRequestPreferences RequestPreferences
{
get
{
if (requestPreferences == null)
{
requestPreferences = new RequestPreferences(this);
}
return requestPreferences;
}
}
public string ContentType { get; set; }
public bool IsLocal { get; private set; }
public string ResponseContentType { get; set; }
public bool HasExplicitResponseContentType { get; set; }
public string CompressionType { get; set; }
public string AbsoluteUri { get; set; }
public string PathInfo { get; set; }
public IHttpFile[] Files { get; set; }
public Uri UrlReferrer { get; set; }
public INameValueCollection Headers { get; set; }
public INameValueCollection QueryString { get; set; }
public INameValueCollection FormData { get; set; }
public bool UseBufferedStream { get; set; }
private string body;
public string GetRawBody()
{
return body ?? (body = (Message.Body ?? "").Dump());
}
public string RawUrl { get; set; }
public string RemoteIp { get; set; }
public string Authorization { get; set; }
public bool IsSecureConnection { get; set; }
public string[] AcceptTypes { get; set; }
public Stream InputStream { get; set; }
public long ContentLength
{
get { return (GetRawBody() ?? "").Length; }
}
public BasicRequest PopulateWith(IRequest request)
{
this.Headers = request.Headers;
this.Cookies = request.Cookies;
this.Items = request.Items;
this.UserAgent = request.UserAgent;
this.RemoteIp = request.RemoteIp;
this.UserHostAddress = request.UserHostAddress;
this.IsSecureConnection = request.IsSecureConnection;
this.AcceptTypes = request.AcceptTypes;
return this;
}
}
}