* HttpChannel.cs, HttpClientChannel.cs: Added missing IDictionary
[mono.git] / mcs / class / System.Runtime.Remoting / System.Runtime.Remoting.Channels.Http / HttpRemotingHandlerFactory.cs
1 //
2 // System.Runtime.Remoting.Channels.Http.HttpRemotingHandlerFactory
3 //
4 // Authors:
5 //      Martin Willemoes Hansen (mwh@sysrq.dk)
6 //      Lluis Sanchez Gual (lluis@ximian.com)
7 //
8 // (C) 2003 Martin Willemoes Hansen
9 //
10
11 using System.Web;
12 using System.IO;
13 using System.Runtime.Remoting;
14 using System.Runtime.Remoting.Channels;
15
16 namespace System.Runtime.Remoting.Channels.Http 
17 {
18         public class HttpRemotingHandlerFactory : IHttpHandlerFactory
19         {
20                 static bool webConfigLoaded = false;
21                 static HttpServerTransportSink transportSink = null;
22                 
23                 public HttpRemotingHandlerFactory ()
24                 {
25                 }
26
27                 public IHttpHandler GetHandler (HttpContext context,
28                                                 string verb,
29                                                 string url,
30                                                 string filePath)
31                 {
32                         if (!webConfigLoaded)
33                                 ConfigureHttpChannel (context);
34                         
35                         return new HttpRemotingHandler (transportSink);
36                 }
37                 
38                 void ConfigureHttpChannel (HttpContext context)
39                 {
40                         lock (GetType())
41                         {
42                                 if (webConfigLoaded) return;
43                                 
44                                 // Look for a channel that wants to receive http request
45                                 
46                                 foreach (IChannel channel in ChannelServices.RegisteredChannels)
47                                 {
48                                         IChannelReceiverHook chook = channel as IChannelReceiverHook;
49                                         if (chook == null) continue;
50                                         
51                                         if (chook.ChannelScheme != "http")
52                                                 throw new RemotingException ("Only http channels are allowed when hosting remoting objects in a web server");
53                                         
54                                         if (!chook.WantsToListen) continue;
55                                         
56                                         // Register the uri for the channel. The channel uri includes the scheme, the
57                                         // host and the application path
58                                         
59                                         string channelUrl = context.Request.Url.GetLeftPart(UriPartial.Authority);
60                                         channelUrl += context.Request.ApplicationPath;
61                                         chook.AddHookChannelUri (channelUrl);
62                                         
63                                         transportSink = new HttpServerTransportSink (chook.ChannelSinkChain, null);
64                                 }
65                                 webConfigLoaded = true;
66                         }
67                 }
68
69                 public void ReleaseHandler (IHttpHandler handler)
70                 {
71                 }
72         }
73 }