[LoongArch64] Part-5:add loongarch support in some files for LoongArch64. (#21769)
[mono-project.git] / mcs / class / System.Runtime.Remoting / System.Runtime.Remoting.Channels.Http / HttpChannel.cs
blob83936faee9e2dc2536f8dfc5ffe0546aac2b8a02
1 //
2 // HttpChannel.cs
3 //
4 // Author:
5 // Michael Hutchinson <mhutchinson@novell.com>
6 //
7 // Copyright (C) 2008 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System.Collections;
30 using System.Runtime.Remoting.Messaging;
32 namespace System.Runtime.Remoting.Channels.Http
35 public class HttpChannel : BaseChannelWithProperties,
36 IChannel, IChannelReceiver, IChannelReceiverHook, IChannelSender
37 , ISecurableChannel
39 HttpClientChannel client;
40 HttpServerChannel server;
41 string name = "http";
43 #region Constructors
45 public HttpChannel ()
47 client = new HttpClientChannel ();
48 server = new HttpServerChannel ();
51 public HttpChannel (int port)
53 client = new HttpClientChannel ();
54 server = new HttpServerChannel (port);
57 public HttpChannel (IDictionary properties,
58 IClientChannelSinkProvider clientSinkProvider,
59 IServerChannelSinkProvider serverSinkProvider)
61 if (properties != null && properties.Contains ("name")) {
62 this.name = (string)properties["name"];
65 client = new HttpClientChannel (properties, clientSinkProvider);
66 server = new HttpServerChannel (properties, serverSinkProvider);
69 #endregion
71 #region BaseChannelWithProperties overrides
73 public override object this[object key]
75 get { return Properties[key]; }
76 set { Properties[key] = value; }
79 public override ICollection Keys
81 get { return Properties.Keys; }
84 public override IDictionary Properties
86 get
88 return new AggregateDictionary (new IDictionary[] {
89 client.Properties,
90 server.Properties
91 });
95 #endregion
97 #region IChannel
99 public string ChannelName
101 get { return name; }
104 public int ChannelPriority
106 get { return server.ChannelPriority; }
109 public string Parse (string url, out string objectURI)
111 return ParseInternal (url, out objectURI);
114 internal static string ParseInternal (string url, out string objectURI)
116 if (url == null)
117 throw new ArgumentNullException ("url");
119 // format: "http://host:port/path/to/object"
120 objectURI = null;
122 // url needs to be at least "http:" or "https:"
123 if (url.Length < 5 ||
124 (url[0] != 'H' && url[0] != 'h') ||
125 (url[1] != 'T' && url[1] != 't') ||
126 (url[2] != 'T' && url[2] != 't') ||
127 (url[3] != 'P' && url[3] != 'p'))
128 return null;
130 int protolen;
131 if (url[4] == 'S' || url[4] == 's') {
132 if (url.Length < 6)
133 return null;
135 protolen = 5;
136 } else {
137 protolen = 4;
140 if (url[protolen] != ':')
141 return null;
143 // "http:" and "https:" are acceptable inputs
144 if (url.Length == protolen + 1)
145 return url;
147 // protocol must be followed by "//"
148 if (url.Length < protolen + 3 || url[protolen + 1] != '/' || url[protolen + 2] != '/')
149 return null;
151 // "http://" and "https://" are acceptable inputs
152 if (url.Length == protolen + 3)
153 return url;
155 int slash = url.IndexOf ('/', protolen + 3);
156 if (slash == -1)
157 return url;
159 objectURI = url.Substring (slash);
161 return url.Substring (0, slash);
164 #endregion
166 #region IChannelReceiver (: IChannel)
168 public object ChannelData
170 get { return server.ChannelData; }
173 public string[] GetUrlsForUri (string objectURI)
175 return server.GetUrlsForUri (objectURI);
178 public void StartListening (object data)
180 server.StartListening (data);
183 public void StopListening (object data)
185 server.StopListening (data);
188 #endregion
190 #region IChannelReceiverHook
192 public void AddHookChannelUri (string channelUri)
194 server.AddHookChannelUri (channelUri);
197 public string ChannelScheme
199 get { return server.ChannelScheme; }
202 public IServerChannelSink ChannelSinkChain
204 get { return server.ChannelSinkChain; }
207 public bool WantsToListen
209 get { return server.WantsToListen; }
210 set { server.WantsToListen = value; }
213 #endregion
215 #region IChannelSender (: IChannel)
217 public IMessageSink CreateMessageSink (string url, object remoteChannelData, out string objectURI)
219 return client.CreateMessageSink (url, remoteChannelData, out objectURI);
222 #endregion
224 #region ISecurableChannel
226 public bool IsSecured
228 get { return client.IsSecured; }
229 set { client.IsSecured = value; }
232 #endregion