HttpRemotingHandler.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. // System.Runtime.Remoting.Channels.Http.HttpRemotingHandler
  3. //
  4. // Authors:
  5. // Martin Willemoes Hansen ([email protected])
  6. // Lluis Sanchez Gual ([email protected])
  7. //
  8. // (C) 2003 Martin Willemoes Hansen
  9. //
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. using System;
  31. using System.IO;
  32. using System.Web;
  33. namespace System.Runtime.Remoting.Channels.Http
  34. {
  35. public class HttpRemotingHandler : IHttpHandler
  36. {
  37. HttpServerTransportSink transportSink;
  38. public HttpRemotingHandler ()
  39. {
  40. }
  41. [MonoTODO]
  42. public HttpRemotingHandler (Type type, object srvID)
  43. {
  44. throw new NotImplementedException ();
  45. }
  46. internal HttpRemotingHandler (HttpServerTransportSink sink)
  47. {
  48. transportSink = sink;
  49. }
  50. public bool IsReusable {
  51. get { return true; }
  52. }
  53. public void ProcessRequest (HttpContext context)
  54. {
  55. HttpRequest request = context.Request;
  56. HttpResponse response = context.Response;
  57. // Create transport headers for the request
  58. TransportHeaders theaders = new TransportHeaders();
  59. string objectUri = request.RawUrl;
  60. objectUri = objectUri.Substring (request.ApplicationPath.Length); // application path is not part of the uri
  61. theaders ["__RequestUri"] = objectUri;
  62. theaders ["Content-Type"] = request.ContentType;
  63. theaders ["__RequestVerb"]= request.HttpMethod;
  64. theaders ["__HttpVersion"] = request.Headers ["http-version"];
  65. theaders ["User-Agent"] = request.UserAgent;
  66. theaders ["Host"] = request.Headers ["host"];
  67. ITransportHeaders responseHeaders;
  68. Stream responseStream;
  69. // Dispatch the request
  70. transportSink.DispatchRequest (request.InputStream, theaders, out responseStream, out responseHeaders);
  71. // Write the response
  72. if (responseHeaders != null && responseHeaders["__HttpStatusCode"] != null)
  73. {
  74. // The formatter can set the status code
  75. response.StatusCode = int.Parse ((string) responseHeaders["__HttpStatusCode"]);
  76. response.StatusDescription = (string) responseHeaders["__HttpReasonPhrase"];
  77. }
  78. byte[] bodyBuffer = bodyBuffer = new byte [responseStream.Length];
  79. responseStream.Seek (0, SeekOrigin.Begin);
  80. int nr = 0;
  81. while (nr < responseStream.Length)
  82. nr += responseStream.Read (bodyBuffer, nr, bodyBuffer.Length - nr);
  83. response.OutputStream.Write (bodyBuffer, 0, bodyBuffer.Length);
  84. }
  85. }
  86. }