2010-04-14 10:28:33 -07:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Web;
|
|
|
|
|
using System.Web.Hosting;
|
|
|
|
|
using Orchard.Specs.Util;
|
|
|
|
|
|
|
|
|
|
namespace Orchard.Specs.Hosting
|
|
|
|
|
{
|
|
|
|
|
public static class RequestExtensions
|
|
|
|
|
{
|
|
|
|
|
public static RequestDetails SendRequest(this WebHost webHost, string urlPath)
|
|
|
|
|
{
|
2010-04-14 12:50:00 -07:00
|
|
|
|
var physicalPath = Bleroy.FluentPath.Path.Get(webHost.PhysicalDirectory);
|
2010-04-14 10:28:33 -07:00
|
|
|
|
|
|
|
|
|
var details = new RequestDetails
|
|
|
|
|
{
|
|
|
|
|
Page = physicalPath
|
|
|
|
|
.Combine(urlPath.TrimStart('/', '\\'))
|
|
|
|
|
.GetRelativePath(physicalPath)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
webHost.Execute(() =>
|
|
|
|
|
{
|
|
|
|
|
var output = new StringWriter();
|
2010-04-14 18:22:23 -07:00
|
|
|
|
HttpRuntime.ProcessRequest(new Worker(details, output));
|
2010-04-14 10:28:33 -07:00
|
|
|
|
details.ResponseText = output.ToString();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return details;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Worker : SimpleWorkerRequest
|
|
|
|
|
{
|
2010-04-14 18:22:23 -07:00
|
|
|
|
private readonly RequestDetails _details;
|
|
|
|
|
private readonly TextWriter _output;
|
2010-04-14 10:28:33 -07:00
|
|
|
|
|
|
|
|
|
public Worker(RequestDetails details, TextWriter output)
|
|
|
|
|
: base(details.Page, details.Query, output)
|
|
|
|
|
{
|
|
|
|
|
_details = details;
|
|
|
|
|
_output = output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void SendStatus(int statusCode, string statusDescription)
|
|
|
|
|
{
|
|
|
|
|
_details.StatusCode = statusCode;
|
|
|
|
|
_details.StatusDescription = statusDescription;
|
|
|
|
|
|
|
|
|
|
base.SendStatus(statusCode, statusDescription);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void SendResponseFromFile(string filename, long offset, long length)
|
|
|
|
|
{
|
|
|
|
|
_output.Write(File.ReadAllText(filename));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-04-14 18:22:23 -07:00
|
|
|
|
|