29 using System.Collections;
30 using System.Collections.Generic;
31 using System.Collections.Specialized;
34 using System.Reflection;
40 namespace OpenSim.Framework.Servers.HttpServer
44 private static readonly ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46 protected IHttpRequest _request = null;
47 protected IHttpClientContext _context = null;
49 public string[] AcceptTypes
51 get {
return _request.AcceptTypes; }
54 public Encoding ContentEncoding
56 get {
return _contentEncoding; }
58 private Encoding _contentEncoding;
60 public long ContentLength
62 get {
return _request.ContentLength; }
65 public long ContentLength64
67 get {
return ContentLength; }
70 public string ContentType
72 get {
return _contentType; }
74 private string _contentType;
76 public HttpCookieCollection Cookies
80 RequestCookies cookies = _request.Cookies;
81 HttpCookieCollection httpCookies =
new HttpCookieCollection();
82 foreach (RequestCookie cookie
in cookies)
83 httpCookies.Add(
new HttpCookie(cookie.Name, cookie.Value));
88 public bool HasEntityBody
90 get {
return _request.ContentLength != 0; }
93 public NameValueCollection Headers
95 get {
return _request.Headers; }
98 public string HttpMethod
100 get {
return _request.Method; }
103 public Stream InputStream
105 get {
return _request.Body; }
108 public bool IsSecured
110 get {
return _context.IsSecured; }
113 public bool KeepAlive
115 get {
return ConnectionType.KeepAlive == _request.Connection; }
118 public NameValueCollection QueryString
120 get {
return _queryString; }
122 private NameValueCollection _queryString;
124 public Hashtable Query
126 get {
return _query; }
128 private Hashtable _query;
137 get {
return _request.Uri.AbsolutePath; }
140 public IPEndPoint RemoteIPEndPoint
142 get {
return _remoteIPEndPoint; }
144 private IPEndPoint _remoteIPEndPoint;
148 get {
return _request.Uri; }
151 public string UserAgent
153 get {
return _userAgent; }
155 private string _userAgent;
157 internal IHttpRequest IHttpRequest
159 get {
return _request; }
162 internal IHttpClientContext IHttpClientContext
164 get {
return _context; }
171 internal Dictionary<string, object> Whiteboard
173 get {
return _whiteboard; }
175 private Dictionary<string, object> _whiteboard =
new Dictionary<string, object>();
184 if (null != req.Headers[
"content-encoding"])
188 _contentEncoding = Encoding.GetEncoding(_request.Headers[
"content-encoding"]);
196 if (null != req.Headers[
"content-type"])
197 _contentType = _request.Headers[
"content-type"];
198 if (null != req.Headers[
"user-agent"])
199 _userAgent = req.Headers[
"user-agent"];
201 if (null != req.Headers[
"remote_addr"])
205 IPAddress addr = IPAddress.Parse(req.Headers[
"remote_addr"]);
208 string[] strPorts = req.Headers[
"remote_port"].Split(
new char[] {
',' });
209 if (strPorts.Length > 1)
211 _log.ErrorFormat(
"[OSHttpRequest]: format exception on addr/port {0}:{1}, ignoring",
212 req.Headers[
"remote_addr"], req.Headers[
"remote_port"]);
214 int port = Int32.Parse(strPorts[0]);
215 _remoteIPEndPoint =
new IPEndPoint(addr, port);
217 catch (FormatException)
219 _log.ErrorFormat(
"[OSHttpRequest]: format exception on addr/port {0}:{1}, ignoring",
220 req.Headers[
"remote_addr"], req.Headers[
"remote_port"]);
224 _queryString =
new NameValueCollection();
225 _query =
new Hashtable();
228 foreach (HttpInputItem item
in req.QueryString)
232 _queryString.Add(item.Name, item.Value);
233 _query[item.Name] = item.Value;
235 catch (InvalidCastException)
237 _log.DebugFormat(
"[OSHttpRequest]: error parsing {0} query item, skipping it", item.Name);
244 _log.ErrorFormat(
"[OSHttpRequest]: Error parsing querystring");
257 StringBuilder me =
new StringBuilder();
258 me.Append(String.Format(
"OSHttpRequest: {0} {1}\n", HttpMethod, RawUrl));
259 foreach (
string k
in Headers.AllKeys)
261 me.Append(String.Format(
" {0}: {1}\n", k, Headers[k]));
263 if (null != RemoteIPEndPoint)
265 me.Append(String.Format(
" IP: {0}\n", RemoteIPEndPoint));
268 return me.ToString();
OSHttpRequest(IHttpClientContext context, IHttpRequest req)
override string ToString()