HttpRemotingHandler.cs 2.1 KB

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