From 920a26eeec07ea35cdade694649c7cc582945c9a Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Mon, 13 Apr 2020 15:01:04 +0100 Subject: [PATCH] add request QueryFlags --- .../HttpServer/Interfaces/IOSHttpRequest.cs | 1 + .../Servers/HttpServer/OSHttpRequest.cs | 102 ++++++++++-------- .../Tests/Common/Mock/TestOSHttpRequest.cs | 8 ++ 3 files changed, 68 insertions(+), 43 deletions(-) diff --git a/OpenSim/Framework/Servers/HttpServer/Interfaces/IOSHttpRequest.cs b/OpenSim/Framework/Servers/HttpServer/Interfaces/IOSHttpRequest.cs index 39dc6faa56..70f3199fc1 100644 --- a/OpenSim/Framework/Servers/HttpServer/Interfaces/IOSHttpRequest.cs +++ b/OpenSim/Framework/Servers/HttpServer/Interfaces/IOSHttpRequest.cs @@ -52,6 +52,7 @@ namespace OpenSim.Framework.Servers.HttpServer bool KeepAlive { get; } NameValueCollection QueryString { get; } Hashtable Query { get; } + HashSet QueryFlags { get; } Dictionary QueryAsDictionary { get; } //faster than Query string RawUrl { get; } IPEndPoint RemoteIPEndPoint { get; } diff --git a/OpenSim/Framework/Servers/HttpServer/OSHttpRequest.cs b/OpenSim/Framework/Servers/HttpServer/OSHttpRequest.cs index 0da0577a4a..0ba39a6630 100644 --- a/OpenSim/Framework/Servers/HttpServer/OSHttpRequest.cs +++ b/OpenSim/Framework/Servers/HttpServer/OSHttpRequest.cs @@ -43,23 +43,23 @@ namespace OpenSim.Framework.Servers.HttpServer { private static readonly ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - protected IHttpRequest _request = null; - protected IHttpClientContext _context = null; + protected IHttpRequest m_request = null; + protected IHttpClientContext m_context = null; public string[] AcceptTypes { - get { return _request.AcceptTypes; } + get { return m_request.AcceptTypes; } } public Encoding ContentEncoding { - get { return _contentEncoding; } + get { return m_contentEncoding; } } - private Encoding _contentEncoding; + private Encoding m_contentEncoding; public long ContentLength { - get { return _request.ContentLength; } + get { return m_request.ContentLength; } } public long ContentLength64 @@ -69,15 +69,15 @@ namespace OpenSim.Framework.Servers.HttpServer public string ContentType { - get { return _contentType; } + get { return m_contentType; } } - private string _contentType; + private string m_contentType; public HttpCookieCollection Cookies { get { - RequestCookies cookies = _request.Cookies; + RequestCookies cookies = m_request.Cookies; HttpCookieCollection httpCookies = new HttpCookieCollection(); if(cookies != null) { @@ -90,47 +90,47 @@ namespace OpenSim.Framework.Servers.HttpServer public bool HasEntityBody { - get { return _request.ContentLength != 0; } + get { return m_request.ContentLength != 0; } } public NameValueCollection Headers { - get { return _request.Headers; } + get { return m_request.Headers; } } public string HttpMethod { - get { return _request.Method; } + get { return m_request.Method; } } public Stream InputStream { - get { return _request.Body; } + get { return m_request.Body; } } public bool IsSecured { - get { return _context.IsSecured; } + get { return m_context.IsSecured; } } public bool KeepAlive { - get { return ConnectionType.KeepAlive == _request.Connection; } + get { return ConnectionType.KeepAlive == m_request.Connection; } } public NameValueCollection QueryString { - get { return _request.QueryString;} + get { return m_request.QueryString;} } - private Hashtable _queryAsHashtable = null; + private Hashtable m_queryAsHashtable = null; public Hashtable Query { get { - if (_queryAsHashtable == null) + if (m_queryAsHashtable == null) BuildQueryHashtable(); - return _queryAsHashtable; + return m_queryAsHashtable; } } @@ -146,45 +146,55 @@ namespace OpenSim.Framework.Servers.HttpServer } } - /// - /// POST request values, if applicable - /// -// public Hashtable Form { get; private set; } - - public string RawUrl + private HashSet m_queryFlags = null; + public HashSet QueryFlags { - get { return _request.Uri.AbsolutePath; } + get + { + if (m_queryFlags == null) + BuildQueryDictionary(); + return m_queryFlags; + } + } + /// + /// POST request values, if applicable + /// + // public Hashtable Form { get; private set; } + + public string RawUrl + { + get { return m_request.Uri.AbsolutePath; } } public IPEndPoint RemoteIPEndPoint { - get { return _request.RemoteIPEndPoint; } + get { return m_request.RemoteIPEndPoint; } } public IPEndPoint LocalIPEndPoint { - get { return _request.LocalIPEndPoint; } + get { return m_request.LocalIPEndPoint; } } public Uri Url { - get { return _request.Uri; } + get { return m_request.Uri; } } public string UserAgent { - get { return _userAgent; } + get { return m_userAgent; } } - private string _userAgent; + private string m_userAgent; internal IHttpRequest IHttpRequest { - get { return _request; } + get { return m_request; } } internal IHttpClientContext IHttpClientContext { - get { return _context; } + get { return m_context; } } /// @@ -201,14 +211,14 @@ namespace OpenSim.Framework.Servers.HttpServer public OSHttpRequest(IHttpClientContext context, IHttpRequest req) { - _request = req; - _context = context; + m_request = req; + m_context = context; if (null != req.Headers["content-encoding"]) { try { - _contentEncoding = Encoding.GetEncoding(_request.Headers["content-encoding"]); + m_contentEncoding = Encoding.GetEncoding(m_request.Headers["content-encoding"]); } catch { @@ -217,9 +227,9 @@ namespace OpenSim.Framework.Servers.HttpServer } if (null != req.Headers["content-type"]) - _contentType = _request.Headers["content-type"]; + m_contentType = m_request.Headers["content-type"]; if (null != req.Headers["user-agent"]) - _userAgent = req.Headers["user-agent"]; + m_userAgent = req.Headers["user-agent"]; // Form = new Hashtable(); // foreach (HttpInputItem item in req.Form) @@ -231,8 +241,9 @@ namespace OpenSim.Framework.Servers.HttpServer private void BuildQueryDictionary() { - NameValueCollection q = _request.QueryString; - _queryAsDictionay = new Dictionary(); // only key value pairs + NameValueCollection q = m_request.QueryString; + _queryAsDictionay = new Dictionary(); + m_queryFlags = new HashSet(); for(int i = 0; i (); for (int i = 0; i < q.Count; ++i) { try { var name = q.GetKey(i); if (!string.IsNullOrEmpty(name)) - _queryAsDictionay[name] = q[i]; + m_queryAsHashtable[name] = q[i]; + else + m_queryFlags.Add(q[i]); } catch { } } diff --git a/OpenSim/Tests/Common/Mock/TestOSHttpRequest.cs b/OpenSim/Tests/Common/Mock/TestOSHttpRequest.cs index 21db639817..e0330e7329 100644 --- a/OpenSim/Tests/Common/Mock/TestOSHttpRequest.cs +++ b/OpenSim/Tests/Common/Mock/TestOSHttpRequest.cs @@ -153,6 +153,14 @@ namespace OpenSim.Tests.Common } } + public HashSet QueryFlags + { + get + { + throw new NotImplementedException(); + } + } + public string RawUrl { get