1 //==========================================================================
4 // Summary: Implements Helper internal class for transmission over HTTP.
6 // Classes: internal HttpHelper
9 // Ahmad Tantawy popsito82@hotmail.com
10 // Ahmad Kadry kadrianoz@hotmail.com
11 // Hussein Mehanna hussein_mehanna@hotmail.com
13 //==========================================================================
16 // Permission is hereby granted, free of charge, to any person obtaining
17 // a copy of this software and associated documentation files (the
18 // "Software"), to deal in the Software without restriction, including
19 // without limitation the rights to use, copy, modify, merge, publish,
20 // distribute, sublicense, and/or sell copies of the Software, and to
21 // permit persons to whom the Software is furnished to do so, subject to
22 // the following conditions:
24 // The above copyright notice and this permission notice shall be
25 // included in all copies or substantial portions of the Software.
27 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
31 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
32 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
33 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 using System.Globalization;
41 using System.Text.RegularExpressions;
43 namespace System.Runtime.Remoting.Channels.Http
45 internal class HttpHelper
47 public static string Parse(string URL , out string ObjectURI)
51 string ChannelURI = null;
53 Pos = IndexOfChannelUri (URL);
56 Pos = URL.IndexOf("/", Pos);
59 ObjectURI = URL.Substring(Pos);
60 ChannelURI = URL.Substring(0, Pos);
62 else ChannelURI = URL;
68 static int IndexOfChannelUri(string URL)
70 CompareInfo ci = CultureInfo.InvariantCulture.CompareInfo;
72 if (ci.IsPrefix (URL, "http://", CompareOptions.IgnoreCase))
73 return "http://".Length;
75 if (ci.IsPrefix (URL, "https://", CompareOptions.IgnoreCase))
76 return "https://".Length;
81 public static bool StartsWithHttp (string url)
83 return IndexOfChannelUri (url) > 0;
86 public static void CopyStream (Stream inStream, Stream outStream)
88 byte[] buffer = new byte [1024];
91 while ((nr = inStream.Read (buffer, 0, buffer.Length)) > 0)
92 outStream.Write (buffer, 0, nr);
96 if (outStream.CanSeek)
97 outStream.Seek (0,SeekOrigin.Begin);
100 public static String GetHostName()
102 string hostName = Dns.GetHostName();
104 if (hostName == null)
106 throw new ArgumentNullException("hostName");
112 public static String GetMachineName()
115 String machineName = GetHostName();
116 if (machineName != null)
117 machineName= Dns.GetHostByName(machineName).HostName;
119 if (machineName== null)
121 throw new ArgumentNullException("machine");