* Started work on converting BaseHttpServer to a stream dispatcher
parent
bd8018fa1c
commit
8b3cb93b49
|
@ -65,6 +65,7 @@ namespace OpenSim.Framework.Servers
|
|||
protected HttpListener m_httpListener;
|
||||
protected Dictionary<string, RestMethodEntry> m_restHandlers = new Dictionary<string, RestMethodEntry>();
|
||||
protected Dictionary<string, XmlRpcMethod> m_rpcHandlers = new Dictionary<string, XmlRpcMethod>();
|
||||
protected Dictionary<string, IStreamHandler> m_streamHandlers = new Dictionary<string, IStreamHandler>();
|
||||
protected int m_port;
|
||||
protected bool firstcaps = true;
|
||||
|
||||
|
@ -73,6 +74,11 @@ namespace OpenSim.Framework.Servers
|
|||
m_port = port;
|
||||
}
|
||||
|
||||
private void AddStreamHandler(string path, IStreamHandler handler)
|
||||
{
|
||||
m_streamHandlers.Add(path, handler);
|
||||
}
|
||||
|
||||
public bool AddRestHandler(string method, string path, RestMethod handler)
|
||||
{
|
||||
//Console.WriteLine("adding new REST handler for path " + path);
|
||||
|
@ -189,8 +195,6 @@ namespace OpenSim.Framework.Servers
|
|||
}
|
||||
|
||||
public virtual void HandleRequest(Object stateinfo)
|
||||
{
|
||||
try
|
||||
{
|
||||
HttpListenerContext context = (HttpListenerContext)stateinfo;
|
||||
|
||||
|
@ -200,7 +204,51 @@ namespace OpenSim.Framework.Servers
|
|||
response.KeepAlive = false;
|
||||
response.SendChunked = false;
|
||||
|
||||
string path = request.RawUrl;
|
||||
|
||||
IStreamHandler streamHandler;
|
||||
|
||||
if(TryGetStreamHandler(path, out streamHandler))
|
||||
{
|
||||
streamHandler.Handle(path, request.InputStream, response.OutputStream );
|
||||
}
|
||||
else
|
||||
{
|
||||
HandleLegacyRequests(request, response);
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryGetStreamHandler(string path, out IStreamHandler streamHandler )
|
||||
{
|
||||
string bestMatch = null;
|
||||
|
||||
foreach (string pattern in m_streamHandlers.Keys)
|
||||
{
|
||||
if (path.StartsWith(pattern))
|
||||
{
|
||||
if (String.IsNullOrEmpty( bestMatch ) || pattern.Length > bestMatch.Length)
|
||||
{
|
||||
bestMatch = pattern;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( String.IsNullOrEmpty( bestMatch ) )
|
||||
{
|
||||
streamHandler = null;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
streamHandler = m_streamHandlers[bestMatch];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleLegacyRequests(HttpListenerRequest request, HttpListenerResponse response)
|
||||
{
|
||||
Stream body = request.InputStream;
|
||||
|
||||
Encoding encoding = Encoding.UTF8;
|
||||
StreamReader reader = new StreamReader(body, encoding);
|
||||
|
||||
|
@ -250,14 +298,12 @@ namespace OpenSim.Framework.Servers
|
|||
Stream output = response.OutputStream;
|
||||
response.SendChunked = false;
|
||||
response.ContentLength64 = buffer.Length;
|
||||
|
||||
|
||||
|
||||
output.Write(buffer, 0, buffer.Length);
|
||||
output.Close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
//Console.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
|
@ -291,9 +337,5 @@ namespace OpenSim.Framework.Servers
|
|||
}
|
||||
}
|
||||
|
||||
public void AddLlsdMethod<TResponse, TRequest>(string path, LlsdMethod<TResponse, TRequest> handler )
|
||||
{
|
||||
throw new Exception("The method or operation is not implemented.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace OpenSim.Framework.Servers
|
||||
{
|
||||
public interface IStreamHandler
|
||||
{
|
||||
void Handle(string path, Stream request, Stream response);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ProjectType>Local</ProjectType>
|
||||
<ProductVersion>8.0.50727</ProductVersion>
|
||||
|
@ -6,7 +6,8 @@
|
|||
<ProjectGuid>{2CC71860-0000-0000-0000-000000000000}</ProjectGuid>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ApplicationIcon></ApplicationIcon>
|
||||
<ApplicationIcon>
|
||||
</ApplicationIcon>
|
||||
<AssemblyKeyContainerName>
|
||||
</AssemblyKeyContainerName>
|
||||
<AssemblyName>OpenSim.Framework.Servers</AssemblyName>
|
||||
|
@ -15,9 +16,11 @@
|
|||
<DefaultTargetSchema>IE50</DefaultTargetSchema>
|
||||
<DelaySign>false</DelaySign>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder></AppDesignerFolder>
|
||||
<AppDesignerFolder>
|
||||
</AppDesignerFolder>
|
||||
<RootNamespace>OpenSim.Framework.Servers</RootNamespace>
|
||||
<StartupObject></StartupObject>
|
||||
<StartupObject>
|
||||
</StartupObject>
|
||||
<FileUpgradeFlags>
|
||||
</FileUpgradeFlags>
|
||||
</PropertyGroup>
|
||||
|
@ -28,7 +31,8 @@
|
|||
<ConfigurationOverrideFile>
|
||||
</ConfigurationOverrideFile>
|
||||
<DefineConstants>TRACE;DEBUG</DefineConstants>
|
||||
<DocumentationFile></DocumentationFile>
|
||||
<DocumentationFile>
|
||||
</DocumentationFile>
|
||||
<DebugSymbols>True</DebugSymbols>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<Optimize>False</Optimize>
|
||||
|
@ -37,7 +41,8 @@
|
|||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
||||
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<NoWarn></NoWarn>
|
||||
<NoWarn>
|
||||
</NoWarn>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
|
||||
|
@ -46,7 +51,8 @@
|
|||
<ConfigurationOverrideFile>
|
||||
</ConfigurationOverrideFile>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<DocumentationFile></DocumentationFile>
|
||||
<DocumentationFile>
|
||||
</DocumentationFile>
|
||||
<DebugSymbols>False</DebugSymbols>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<Optimize>True</Optimize>
|
||||
|
@ -55,7 +61,8 @@
|
|||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
||||
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<NoWarn></NoWarn>
|
||||
<NoWarn>
|
||||
</NoWarn>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="libsecondlife.dll">
|
||||
|
@ -66,6 +73,7 @@
|
|||
<HintPath>System.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml">
|
||||
<HintPath>System.Xml.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
|
@ -99,12 +107,14 @@
|
|||
<Compile Include="ILlsdMethodHandler.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="IStreamHandler.cs" />
|
||||
<Compile Include="LlsdMethod.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="RestMethod.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="RestStreamHandler.cs" />
|
||||
<Compile Include="UDPServerBase.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace OpenSim.Framework.Servers
|
||||
{
|
||||
public class RestStreamHandler : IStreamHandler
|
||||
{
|
||||
public void Handle( string path, Stream request, Stream response )
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue