SimpleWorkerRequest.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. //
  2. // System.Web.Hosting.SimpleWorkerRequest.cs
  3. //
  4. // Author:
  5. // Miguel de Icaza ([email protected])
  6. //
  7. //
  8. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System;
  30. using System.Collections;
  31. using System.IO;
  32. using System.Runtime.InteropServices;
  33. using System.Web;
  34. using System.Web.UI;
  35. using System.Web.Util;
  36. namespace System.Web.Hosting {
  37. [ComVisible (false)]
  38. public class SimpleWorkerRequest : HttpWorkerRequest {
  39. string page;
  40. string query;
  41. string app_virtual_dir;
  42. string app_physical_dir;
  43. TextWriter output;
  44. bool hosted;
  45. // computed
  46. string raw_url;
  47. //
  48. // Constructor used when the target application domain
  49. // was created with ApplicationHost.CreateApplicationHost
  50. //
  51. public SimpleWorkerRequest (string page, string query, TextWriter output)
  52. {
  53. this.page = page;
  54. this.query = query;
  55. this.output = output;
  56. app_virtual_dir = HttpRuntime.AppDomainAppVirtualPath;
  57. app_physical_dir = HttpRuntime.AppDomainAppPath;
  58. hosted = true;
  59. }
  60. //
  61. // Creates a SimpleWorkerRequest that can be used from any AppDomain
  62. //
  63. // This is used for user instantiates HttpContext (my_SimpleWorkerRequest)
  64. //
  65. public SimpleWorkerRequest (string appVirtualDir, string appPhysicalDir, string page, string query, TextWriter output)
  66. {
  67. this.page = page;
  68. this.query = query;
  69. this.output = output;
  70. app_virtual_dir = appVirtualDir;
  71. app_physical_dir = appPhysicalDir;
  72. }
  73. public override string MachineConfigPath {
  74. get {
  75. if (hosted)
  76. return ICalls.GetMachineConfigPath ();
  77. return null;
  78. }
  79. }
  80. public override string MachineInstallDirectory {
  81. get {
  82. if (hosted)
  83. return ICalls.GetMachineInstallDirectory ();
  84. return null;
  85. }
  86. }
  87. public override void EndOfRequest ()
  88. {
  89. }
  90. public override void FlushResponse (bool finalFlush)
  91. {
  92. }
  93. public override string GetAppPath ()
  94. {
  95. return app_virtual_dir;
  96. }
  97. public override string GetAppPathTranslated ()
  98. {
  99. return app_physical_dir;
  100. }
  101. public override string GetFilePath ()
  102. {
  103. return Path.Combine (app_virtual_dir, page);
  104. }
  105. public override string GetFilePathTranslated ()
  106. {
  107. string local_page;
  108. if (Path.DirectorySeparatorChar == '\\')
  109. local_page = page.Replace ('/', '\\');
  110. else
  111. local_page = page;
  112. return Path.Combine (app_physical_dir, local_page);
  113. }
  114. public override string GetHttpVerbName ()
  115. {
  116. return "GET";
  117. }
  118. public override string GetHttpVersion ()
  119. {
  120. return "HTTP/1.0";
  121. }
  122. public override string GetLocalAddress ()
  123. {
  124. return "127.0.0.1";
  125. }
  126. public override int GetLocalPort ()
  127. {
  128. return 80;
  129. }
  130. public override string GetPathInfo ()
  131. {
  132. return "";
  133. }
  134. public override string GetQueryString ()
  135. {
  136. return query;
  137. }
  138. public override string GetRawUrl ()
  139. {
  140. if (raw_url == null){
  141. string q = ((query == null || query == "") ? "" : "?" + query);
  142. raw_url = Path.Combine (app_virtual_dir, page) + q;
  143. }
  144. return raw_url;
  145. }
  146. public override string GetRemoteAddress ()
  147. {
  148. return "127.0.0.1";
  149. }
  150. public override int GetRemotePort ()
  151. {
  152. return 0;
  153. }
  154. public override string GetServerVariable (string name)
  155. {
  156. return "";
  157. }
  158. public override string GetUriPath ()
  159. {
  160. return app_virtual_dir + "/" + page;
  161. }
  162. public override IntPtr GetUserToken ()
  163. {
  164. return IntPtr.Zero;
  165. }
  166. public override string MapPath (string path)
  167. {
  168. if (!hosted)
  169. return null;
  170. if (!path.StartsWith (app_virtual_dir))
  171. throw new ArgumentNullException ("path is not rooted in the virtual directory");
  172. string rest = path.Substring (app_virtual_dir.Length);
  173. if (rest [0] == '/')
  174. rest = rest.Substring (1);
  175. return Path.Combine (app_physical_dir, rest);
  176. }
  177. public override void SendKnownResponseHeader (int index, string value)
  178. {
  179. }
  180. public override void SendResponseFromFile (IntPtr handle, long offset, long length)
  181. {
  182. }
  183. public override void SendResponseFromFile (string filename, long offset, long length)
  184. {
  185. }
  186. public override void SendResponseFromMemory (byte [] data, int length)
  187. {
  188. }
  189. public override void SendStatus (int statusCode, string statusDescription)
  190. {
  191. }
  192. public override void SendUnknownResponseHeader (string name, string value)
  193. {
  194. }
  195. }
  196. }