Merge pull request #214 from QuickJack/cd2c570c5543963d987f51080218715407c5d4b9
[mono.git] / mcs / class / System.Runtime.Remoting / System.Runtime.Remoting.Channels.Http / HttpRemotingHandler.cs
index 0fd0c75cad9f1e57eecb60127eded5bf2d000552..206b032fe6dbdc1a8624221fb1765d1852f53dac 100644 (file)
@@ -32,6 +32,7 @@
 using System;
 using System.IO;
 using System.Web;
+using System.Collections;
 
 namespace System.Runtime.Remoting.Channels.Http 
 {
@@ -64,12 +65,16 @@ namespace System.Runtime.Remoting.Channels.Http
                        HttpResponse response = context.Response;
                        
                        // Create transport headers for the request
-                       
                        TransportHeaders theaders = new TransportHeaders();
 
                        string objectUri = request.RawUrl;
                        objectUri = objectUri.Substring (request.ApplicationPath.Length);       // application path is not part of the uri
-                       
+                       if (request.ApplicationPath.Length > 0 && 
+                          (objectUri.StartsWith("/") || objectUri.StartsWith(@"\")) )
+                       {
+                               objectUri = objectUri.Substring(1);
+                       }
+
                        theaders ["__RequestUri"] = objectUri;
                        theaders ["Content-Type"] = request.ContentType;
                        theaders ["__RequestVerb"]= request.HttpMethod;
@@ -80,12 +85,16 @@ namespace System.Runtime.Remoting.Channels.Http
                        ITransportHeaders responseHeaders;
                        Stream responseStream;
                        
-                       // Dispatch the request
+                       // Dispatch the request 
+                       ServerProcessing proc = transportSink.SynchronousDispatch 
+                               (theaders, request.InputStream, out responseHeaders, out responseStream);
                        
-                       transportSink.DispatchRequest (request.InputStream, theaders, out responseStream, out responseHeaders);
+                       if (proc == ServerProcessing.Async) {
+                               throw new NotSupportedException ("HttpRemotingHandler does not support async processing in " +
+                                       "the synchronous HTTP pipeline" );
+                       }
 
                        // Write the response
-                       
                        if (responseHeaders != null && responseHeaders["__HttpStatusCode"] != null) 
                        {
                                // The formatter can set the status code
@@ -93,14 +102,19 @@ namespace System.Runtime.Remoting.Channels.Http
                                response.StatusDescription = (string) responseHeaders["__HttpReasonPhrase"];
                        }
                        
-                       byte[] bodyBuffer = bodyBuffer = new byte [responseStream.Length];
-                       responseStream.Seek (0, SeekOrigin.Begin);
-                       
-                       int nr = 0;
-                       while (nr < responseStream.Length)
-                               nr += responseStream.Read (bodyBuffer, nr, bodyBuffer.Length - nr);
+                       if (responseHeaders != null)
+                       {
+                               foreach (DictionaryEntry entry in responseHeaders)
+                               {
+                                       string key = entry.Key.ToString();
+                                       if (key != CommonTransportKeys.HttpStatusCode && key != CommonTransportKeys.HttpReasonPhrase)
+                                               response.AppendHeader(key, entry.Value.ToString());
+                               }
+                       }
                        
-                       response.OutputStream.Write (bodyBuffer, 0, bodyBuffer.Length);
+                       if (responseStream != null) {
+                               HttpClientTransportSink.CopyStream (responseStream, response.OutputStream, 1024);
+                       }
                }
        }       
 }