HttpRemotingHandler.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. using System;
  11. using System.IO;
  12. using System.Web;
  13. namespace System.Runtime.Remoting.Channels.Http
  14. {
  15. public class HttpRemotingHandler : IHttpHandler
  16. {
  17. HttpServerTransportSink transportSink;
  18. public HttpRemotingHandler ()
  19. {
  20. }
  21. [MonoTODO]
  22. public HttpRemotingHandler (Type type, object srvID)
  23. {
  24. throw new NotImplementedException ();
  25. }
  26. internal HttpRemotingHandler (HttpServerTransportSink sink)
  27. {
  28. transportSink = sink;
  29. }
  30. public bool IsReusable {
  31. get { return true; }
  32. }
  33. public void ProcessRequest (HttpContext context)
  34. {
  35. HttpRequest request = context.Request;
  36. HttpResponse response = context.Response;
  37. // Create transport headers for the request
  38. TransportHeaders theaders = new TransportHeaders();
  39. string objectUri = request.RawUrl;
  40. objectUri = objectUri.Substring (request.ApplicationPath.Length); // application path is not part of the uri
  41. theaders ["__RequestUri"] = objectUri;
  42. theaders ["Content-Type"] = request.ContentType;
  43. theaders ["__RequestVerb"]= request.HttpMethod;
  44. theaders ["__HttpVersion"] = request.Headers ["http-version"];
  45. theaders ["User-Agent"] = request.UserAgent;
  46. theaders ["Host"] = request.Headers ["host"];
  47. ITransportHeaders responseHeaders;
  48. Stream responseStream;
  49. // Dispatch the request
  50. transportSink.DispatchRequest (request.InputStream, theaders, out responseStream, out responseHeaders);
  51. // Write the response
  52. if (responseHeaders != null && responseHeaders["__HttpStatusCode"] != null)
  53. {
  54. // The formatter can set the status code
  55. response.StatusCode = int.Parse ((string) responseHeaders["__HttpStatusCode"]);
  56. response.StatusDescription = (string) responseHeaders["__HttpReasonPhrase"];
  57. }
  58. byte[] bodyBuffer = bodyBuffer = new byte [responseStream.Length];
  59. responseStream.Seek (0, SeekOrigin.Begin);
  60. int nr = 0;
  61. while (nr < responseStream.Length)
  62. nr += responseStream.Read (bodyBuffer, nr, bodyBuffer.Length - nr);
  63. response.OutputStream.Write (bodyBuffer, 0, bodyBuffer.Length);
  64. }
  65. }
  66. }