diff options
Diffstat (limited to 'OpenSim/Framework/Servers/OSHttpRequest.cs')
-rw-r--r-- | OpenSim/Framework/Servers/OSHttpRequest.cs | 216 |
1 files changed, 86 insertions, 130 deletions
diff --git a/OpenSim/Framework/Servers/OSHttpRequest.cs b/OpenSim/Framework/Servers/OSHttpRequest.cs index 25da97b..c47fe10 100644 --- a/OpenSim/Framework/Servers/OSHttpRequest.cs +++ b/OpenSim/Framework/Servers/OSHttpRequest.cs | |||
@@ -31,18 +31,25 @@ using System.Collections.Generic; | |||
31 | using System.Collections.Specialized; | 31 | using System.Collections.Specialized; |
32 | using System.Net; | 32 | using System.Net; |
33 | using System.IO; | 33 | using System.IO; |
34 | using System.Reflection; | ||
34 | using System.Text; | 35 | using System.Text; |
35 | using HttpServer; | 36 | using HttpServer; |
37 | using log4net; | ||
36 | 38 | ||
37 | namespace OpenSim.Framework.Servers | 39 | namespace OpenSim.Framework.Servers |
38 | { | 40 | { |
39 | public class OSHttpRequest | 41 | public class OSHttpRequest |
40 | { | 42 | { |
43 | private static readonly ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
44 | |||
45 | protected HttpServer.IHttpRequest _request = null; | ||
46 | protected HttpServer.IHttpClientContext _context = null; | ||
47 | |||
48 | |||
41 | public string[] AcceptTypes | 49 | public string[] AcceptTypes |
42 | { | 50 | { |
43 | get { return _acceptTypes; } | 51 | get { return _request.AcceptTypes; } |
44 | } | 52 | } |
45 | private string[] _acceptTypes; | ||
46 | 53 | ||
47 | public Encoding ContentEncoding | 54 | public Encoding ContentEncoding |
48 | { | 55 | { |
@@ -52,9 +59,8 @@ namespace OpenSim.Framework.Servers | |||
52 | 59 | ||
53 | public long ContentLength | 60 | public long ContentLength |
54 | { | 61 | { |
55 | get { return _contentLength64; } | 62 | get { return _request.ContentLength; } |
56 | } | 63 | } |
57 | private long _contentLength64; | ||
58 | 64 | ||
59 | public long ContentLength64 | 65 | public long ContentLength64 |
60 | { | 66 | { |
@@ -67,101 +73,72 @@ namespace OpenSim.Framework.Servers | |||
67 | } | 73 | } |
68 | private string _contentType; | 74 | private string _contentType; |
69 | 75 | ||
70 | // public CookieCollection Cookies | 76 | public bool HasEntityBody |
71 | // { | 77 | { |
72 | // get { return _cookies; } | 78 | get { return _request.ContentLength != 0; } |
73 | // } | 79 | } |
74 | // private CookieCollection _cookies; | ||
75 | 80 | ||
76 | public NameValueCollection Headers | 81 | public NameValueCollection Headers |
77 | { | 82 | { |
78 | get { return _headers; } | 83 | get { return _request.Headers; } |
79 | } | 84 | } |
80 | private NameValueCollection _headers; | ||
81 | 85 | ||
82 | public string HttpMethod | 86 | public string HttpMethod |
83 | { | 87 | { |
84 | get { return _httpMethod; } | 88 | get { return _request.Method; } |
85 | } | 89 | } |
86 | private string _httpMethod; | ||
87 | 90 | ||
88 | public Stream InputStream | 91 | public Stream InputStream |
89 | { | 92 | { |
90 | get { return _inputStream; } | 93 | get { return _request.Body; } |
91 | } | 94 | } |
92 | private Stream _inputStream; | ||
93 | 95 | ||
94 | // public bool IsSecureConnection | 96 | public bool IsSecured |
95 | // { | ||
96 | // get { return _isSecureConnection; } | ||
97 | // } | ||
98 | // private bool _isSecureConnection; | ||
99 | |||
100 | // public bool IsAuthenticated | ||
101 | // { | ||
102 | // get { return _isAuthenticated; } | ||
103 | // } | ||
104 | // private bool _isAuthenticated; | ||
105 | |||
106 | public bool HasEntityBody | ||
107 | { | 97 | { |
108 | get { return _hasbody; } | 98 | get { return _context.Secured; } |
109 | } | 99 | } |
110 | private bool _hasbody; | ||
111 | 100 | ||
112 | public bool KeepAlive | 101 | public bool KeepAlive |
113 | { | 102 | { |
114 | get { return _keepAlive; } | 103 | get { return ConnectionType.KeepAlive == _request.Connection; } |
115 | } | 104 | } |
116 | private bool _keepAlive; | ||
117 | 105 | ||
118 | public string RawUrl | 106 | public NameValueCollection QueryString |
119 | { | 107 | { |
120 | get { return _rawUrl; } | 108 | get { return _queryString; } |
121 | } | 109 | } |
122 | private string _rawUrl; | 110 | private NameValueCollection _queryString; |
123 | 111 | ||
124 | public Uri Url | 112 | public Hashtable Query |
125 | { | 113 | { |
126 | get { return _url; } | 114 | get { return _query; } |
127 | } | 115 | } |
128 | private Uri _url; | 116 | private Hashtable _query; |
129 | 117 | ||
130 | public string UserAgent | 118 | public string RawUrl |
131 | { | 119 | { |
132 | get { return _userAgent; } | 120 | get { return _request.Uri.AbsolutePath; } |
133 | } | 121 | } |
134 | private string _userAgent; | ||
135 | 122 | ||
136 | public NameValueCollection QueryString | 123 | public IPEndPoint RemoteIPEndPoint |
137 | { | 124 | { |
138 | get { return _queryString; } | 125 | get { return _remoteIPEndPoint; } |
139 | } | 126 | } |
140 | private NameValueCollection _queryString; | 127 | private IPEndPoint _remoteIPEndPoint; |
141 | 128 | ||
142 | public Hashtable Query | 129 | public Uri Url |
143 | { | 130 | { |
144 | get { return _query; } | 131 | get { return _request.Uri; } |
145 | } | 132 | } |
146 | private Hashtable _query; | ||
147 | 133 | ||
148 | public IPEndPoint RemoteIPEndPoint | 134 | public string UserAgent |
149 | { | 135 | { |
150 | get { return _ipEndPoint; } | 136 | get { return _userAgent; } |
151 | } | 137 | } |
152 | private IPEndPoint _ipEndPoint; | 138 | private string _userAgent; |
139 | |||
153 | 140 | ||
154 | // internal HttpRequest HttpRequest | ||
155 | // { | ||
156 | // get { return _request; } | ||
157 | // } | ||
158 | // private HttpRequest _request; | ||
159 | 141 | ||
160 | // internal HttpClientContext HttpClientContext | ||
161 | // { | ||
162 | // get { return _context; } | ||
163 | // } | ||
164 | // private HttpClientContext _context; | ||
165 | 142 | ||
166 | /// <summary> | 143 | /// <summary> |
167 | /// Internal whiteboard for handlers to store temporary stuff | 144 | /// Internal whiteboard for handlers to store temporary stuff |
@@ -173,81 +150,60 @@ namespace OpenSim.Framework.Servers | |||
173 | } | 150 | } |
174 | private Dictionary<string, object> _whiteboard = new Dictionary<string, object>(); | 151 | private Dictionary<string, object> _whiteboard = new Dictionary<string, object>(); |
175 | 152 | ||
153 | |||
176 | public OSHttpRequest() | 154 | public OSHttpRequest() |
177 | { | 155 | { |
178 | } | 156 | } |
179 | 157 | ||
180 | public OSHttpRequest(HttpListenerRequest req) | 158 | public OSHttpRequest(HttpServer.IHttpClientContext context, HttpServer.IHttpRequest req) |
181 | { | 159 | { |
182 | _acceptTypes = req.AcceptTypes; | 160 | _request = req; |
183 | _contentEncoding = req.ContentEncoding; | 161 | _context = context; |
184 | _contentLength64 = req.ContentLength64; | 162 | |
185 | _contentType = req.ContentType; | 163 | if (null != req.Headers["content-encoding"]) |
186 | _headers = req.Headers; | 164 | _contentEncoding = Encoding.GetEncoding(_request.Headers["content-encoding"]); |
187 | _httpMethod = req.HttpMethod; | 165 | if (null != req.Headers["content-type"]) |
188 | _hasbody = req.HasEntityBody; | 166 | _contentType = _request.Headers["content-type"]; |
189 | _inputStream = req.InputStream; | 167 | if (null != req.Headers["user-agent"]) |
190 | _keepAlive = req.KeepAlive; | 168 | _userAgent = req.Headers["user-agent"]; |
191 | _rawUrl = req.RawUrl; | 169 | if (null != req.Headers["remote_addr"]) |
192 | _url = req.Url; | 170 | { |
193 | _queryString = req.QueryString; | 171 | try |
194 | _userAgent = req.UserAgent; | 172 | { |
195 | _ipEndPoint = req.RemoteEndPoint; | 173 | IPAddress addr = IPAddress.Parse(req.Headers["remote_addr"]); |
196 | 174 | int port = Int32.Parse(req.Headers["remote_port"]); | |
197 | // _cookies = req.Cookies; | 175 | _remoteIPEndPoint = new IPEndPoint(addr, port); |
198 | // _isSecureConnection = req.IsSecureConnection; | 176 | } |
199 | // _isAuthenticated = req.IsAuthenticated; | 177 | catch (FormatException) |
200 | } | 178 | { |
179 | _log.ErrorFormat("[OSHttpRequest]: format exception on addr/port {0}:{1}, ignoring", | ||
180 | req.Headers["remote_addr"], req.Headers["remote_port"]); | ||
181 | } | ||
182 | } | ||
201 | 183 | ||
202 | public OSHttpRequest(HttpServer.IHttpClientContext context, HttpServer.IHttpRequest req) | 184 | _queryString = new NameValueCollection(); |
203 | { | 185 | _query = new Hashtable(); |
204 | //_context = context; | 186 | try |
205 | HttpServer.IHttpRequest _request = req; | 187 | { |
206 | 188 | foreach (HttpInputItem item in req.QueryString) | |
207 | _acceptTypes = req.AcceptTypes; | 189 | { |
208 | if (null != req.Headers["content-encoding"]) | 190 | try |
209 | _contentEncoding = Encoding.GetEncoding(_request.Headers["content-encoding"]); | 191 | { |
210 | _contentLength64 = req.ContentLength; | 192 | _queryString.Add(item.Name, item.Value); |
211 | if (null != req.Headers["content-type"]) | 193 | _query[item.Name] = item.Value; |
212 | _contentType = _request.Headers["content-type"]; | 194 | } |
213 | _headers = req.Headers; | 195 | catch (InvalidCastException) |
214 | _httpMethod = req.Method; | 196 | { |
215 | _hasbody = req.ContentLength != 0; | 197 | _log.DebugFormat("[OSHttpRequest]: error parsing {0} query item, skipping it", item.Name); |
216 | _inputStream = req.Body; | 198 | continue; |
217 | _keepAlive = ConnectionType.KeepAlive == req.Connection; | 199 | } |
218 | _rawUrl = req.Uri.AbsolutePath; | 200 | } |
219 | _url = req.Uri; | 201 | } |
220 | if (null != req.Headers["user-agent"]) | 202 | catch (Exception) |
221 | _userAgent = req.Headers["user-agent"]; | 203 | { |
222 | _queryString = new NameValueCollection(); | 204 | _log.ErrorFormat("[OSHttpRequest]: Error parsing querystring"); |
223 | _query = new Hashtable(); | 205 | } |
224 | try | 206 | } |
225 | { | ||
226 | foreach (HttpInputItem item in req.QueryString) | ||
227 | { | ||
228 | try | ||
229 | { | ||
230 | _queryString.Add(item.Name, item.Value); | ||
231 | _query[item.Name] = item.Value; | ||
232 | } | ||
233 | catch (InvalidCastException) | ||
234 | { | ||
235 | System.Console.WriteLine("[OSHttpRequest]: Errror parsing querystring.. but it was recoverable.. skipping on to the next one"); | ||
236 | continue; | ||
237 | } | ||
238 | } | ||
239 | } | ||
240 | catch (Exception) | ||
241 | { | ||
242 | System.Console.WriteLine("[OSHttpRequest]: Errror parsing querystring"); | ||
243 | } | ||
244 | // TODO: requires change to HttpServer.HttpRequest | ||
245 | _ipEndPoint = null; | ||
246 | |||
247 | // _cookies = req.Cookies; | ||
248 | // _isSecureConnection = req.IsSecureConnection; | ||
249 | // _isAuthenticated = req.IsAuthenticated; | ||
250 | } | ||
251 | 207 | ||
252 | public override string ToString() | 208 | public override string ToString() |
253 | { | 209 | { |
@@ -259,7 +215,7 @@ namespace OpenSim.Framework.Servers | |||
259 | } | 215 | } |
260 | if (null != RemoteIPEndPoint) | 216 | if (null != RemoteIPEndPoint) |
261 | { | 217 | { |
262 | me.Append(String.Format(" IP: {0}\n", RemoteIPEndPoint.ToString())); | 218 | me.Append(String.Format(" IP: {0}\n", RemoteIPEndPoint)); |
263 | } | 219 | } |
264 | 220 | ||
265 | return me.ToString(); | 221 | return me.ToString(); |