Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/BloomExe/BloomExe.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ copy /Y "$(SolutionDir)\lib\dotnet\libtidy.dll" $(OutDir)
<PackageReference Include="AWSSDK.S3" Version="3.5.3.10" />
<PackageReference Include="CairoSharp-signed" Version="3.22.24.37" />
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="EmbedIO" Version="3.5.2" />
<PackageReference Include="EPPlus" Version="6.2.4" />
<PackageReference Include="Fleck" Version="1.1.0" />
<PackageReference Include="Glob" Version="1.1.8" />
Expand Down Expand Up @@ -351,4 +352,4 @@ copy /Y "$(SolutionDir)\lib\dotnet\libtidy.dll" $(OutDir)
<Content Include="desktopAndTaskBar.svg.ico" />
<None Include="Resources\bloom.png" />
</ItemGroup>
</Project>
</Project>
99 changes: 88 additions & 11 deletions src/BloomExe/web/BloomHttpListenerContext.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
using System.Net;
using System.IO;
using System.Net;
using EmbedIO;

namespace Bloom.web
{
/// <summary>
/// At this point, the only point of these classes is so we can write tests without having
/// to try to spin up a real HttpListener which causes problems on TeamCity.
/// to try to spin up a real HTTP server which causes problems on TeamCity.
///
/// The Bloom... concrete classes are simply wrappers for the real objects.
/// The Bloom... concrete classes are wrappers for EmbedIO's IHttpContext.
/// </summary>
public interface IHttpListenerContext
{
IHttpListenerRequest Request { get; }
HttpListenerResponse Response { get; }
IHttpListenerResponse Response { get; }
}

public class BloomHttpListenerContext : IHttpListenerContext
{
private readonly HttpListenerContext _actualContext;
private readonly IHttpContext _actualContext;

public BloomHttpListenerContext(HttpListenerContext context)
public BloomHttpListenerContext(IHttpContext context)
{
_actualContext = context;
}
Expand All @@ -28,9 +30,9 @@ public IHttpListenerRequest Request
get { return new BloomHttpListenerRequest(_actualContext.Request); }
}

public HttpListenerResponse Response
public IHttpListenerResponse Response
{
get { return _actualContext.Response; }
get { return new BloomHttpListenerResponse(_actualContext.Response); }
}
}

Expand All @@ -47,9 +49,9 @@ public interface IHttpListenerRequest

public class BloomHttpListenerRequest : IHttpListenerRequest
{
private readonly HttpListenerRequest _actualRequest;
private readonly IHttpRequest _actualRequest;

public BloomHttpListenerRequest(HttpListenerRequest request)
public BloomHttpListenerRequest(IHttpRequest request)
{
_actualRequest = request;
}
Expand All @@ -71,7 +73,7 @@ public bool HasEntityBody

public string HttpMethod
{
get { return _actualRequest.HttpMethod; }
get { return _actualRequest.HttpVerb.ToString(); }
}

public System.IO.Stream InputStream
Expand All @@ -89,4 +91,79 @@ public System.Uri Url
get { return _actualRequest.Url; }
}
}

public interface IHttpListenerResponse
{
string ContentType { get; set; }
long ContentLength64 { get; set; }
int StatusCode { get; set; }
string StatusDescription { get; set; }
Stream OutputStream { get; }
void AppendHeader(string name, string value);
void Close(byte[] buffer, bool willBlock);
void Close();
}

public class BloomHttpListenerResponse : IHttpListenerResponse
{
private readonly IHttpResponse _actualResponse;
private long _contentLength;

public BloomHttpListenerResponse(IHttpResponse response)
{
_actualResponse = response;
}

public string ContentType
{
get { return _actualResponse.ContentType; }
set { _actualResponse.ContentType = value; }
}

public long ContentLength64
{
get { return _contentLength; }
set
{
_contentLength = value;
_actualResponse.ContentLength64 = value;
}
}

public int StatusCode
{
get { return _actualResponse.StatusCode; }
set { _actualResponse.StatusCode = value; }
}

public string StatusDescription
{
get { return _actualResponse.StatusDescription; }
set { _actualResponse.StatusDescription = value; }
}

public Stream OutputStream
{
get { return _actualResponse.OutputStream; }
}

public void AppendHeader(string name, string value)
{
_actualResponse.Headers.Add(name, value);
}

public void Close(byte[] buffer, bool willBlock)
{
if (buffer != null && buffer.Length > 0)
{
_actualResponse.OutputStream.Write(buffer, 0, buffer.Length);
}
_actualResponse.Close();
}

public void Close()
{
_actualResponse.Close();
}
}
}
Loading