Skip to content

Commit

Permalink
Merge branch 'httplistener' into ghfvs-httplistener
Browse files Browse the repository at this point in the history
  • Loading branch information
grokys committed Dec 7, 2017
2 parents 3dfd53f + 61f79ef commit 9fd2de6
Show file tree
Hide file tree
Showing 14 changed files with 1,471 additions and 0 deletions.
Binary file modified src/GlobalSuppressions.cs
Binary file not shown.
1 change: 1 addition & 0 deletions src/Infrastructure/IOperatingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public interface IOperatingSystem
IEnvironment Environment { get; }
IFileFacade File { get; }
IMemoryMappedFileFactory MemoryMappedFiles { get; }
INetFactory Net { get; }
IProcessLocator ProcessLocator { get; }
IProcessStarter ProcessStarter { get; }
IRegistry Registry { get; }
Expand Down
47 changes: 47 additions & 0 deletions src/Net/HttpListenerContextWrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Net;
using System.Net.WebSockets;
using System.Security.Principal;
using System.Threading.Tasks;

namespace Rothko
{
public class HttpListenerContextWrapper : IHttpListenerContext
{
readonly HttpListenerContext inner;

public HttpListenerContextWrapper(HttpListenerContext inner)
{
this.inner = inner;
Request = new HttpListenerRequestWrapper(inner.Request);
Response = new HttpListenerResponseWrapper(inner.Response);
}

public IHttpListenerRequest Request { get; }

public IHttpListenerResponse Response { get; }

public IPrincipal User => inner.User;

public Task<HttpListenerWebSocketContext> AcceptWebSocketAsync(string subProtocol)
{
return inner.AcceptWebSocketAsync(subProtocol);
}

public Task<HttpListenerWebSocketContext> AcceptWebSocketAsync(string subProtocol, TimeSpan keepAliveInterval)
{
return inner.AcceptWebSocketAsync(subProtocol, keepAliveInterval);
}

public Task<HttpListenerWebSocketContext> AcceptWebSocketAsync(string subProtocol, int receiveBufferSize, TimeSpan keepAliveInterval)
{
return inner.AcceptWebSocketAsync(subProtocol, receiveBufferSize, keepAliveInterval);
}

public Task<HttpListenerWebSocketContext> AcceptWebSocketAsync(string subProtocol, int receiveBufferSize, TimeSpan keepAliveInterval,
ArraySegment<byte> internalBuffer)
{
return inner.AcceptWebSocketAsync(subProtocol, receiveBufferSize, keepAliveInterval, internalBuffer);
}
}
}
98 changes: 98 additions & 0 deletions src/Net/HttpListenerRequestWrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using System;
using System.Collections.Specialized;
using System.IO;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;

namespace Rothko
{
public class HttpListenerRequestWrapper : IHttpListenerRequest
{
readonly HttpListenerRequest inner;

public HttpListenerRequestWrapper(HttpListenerRequest inner)
{
this.inner = inner;
}

public string[] AcceptTypes => inner.AcceptTypes;

public int ClientCertificateError => inner.ClientCertificateError;

public Encoding ContentEncoding => inner.ContentEncoding;

public long ContentLength64 => inner.ContentLength64;

public string ContentType => inner.ContentType;

public CookieCollection Cookies => inner.Cookies;

public bool HasEntityBody => inner.HasEntityBody;

public NameValueCollection Headers => inner.Headers;

public string HttpMethod => inner.HttpMethod;

public Stream InputStream => inner.InputStream;

public bool IsAuthenticated => inner.IsAuthenticated;

public bool IsLocal => inner.IsLocal;

public bool IsSecureConnection => inner.IsSecureConnection;

public bool IsWebSocketRequest => inner.IsWebSocketRequest;

public bool KeepAlive => inner.KeepAlive;

public IPEndPoint LocalEndPoint => inner.LocalEndPoint;

public Version ProtocolVersion => inner.ProtocolVersion;

public NameValueCollection QueryString => inner.QueryString;

public string RawUrl => inner.RawUrl;

public IPEndPoint RemoteEndPoint => inner.RemoteEndPoint;

public Guid RequestTraceIdentifier => inner.RequestTraceIdentifier;

public string ServiceName => inner.ServiceName;

public TransportContext TransportContext => inner.TransportContext;

public Uri Url => inner.Url;

public Uri UrlReferrer => inner.UrlReferrer;

public string UserAgent => inner.UserAgent;

public string UserHostAddress => inner.UserHostAddress;

public string UserHostName => inner.UserHostName;

public string[] UserLanguages => inner.UserLanguages;

public IAsyncResult BeginGetClientCertificate(AsyncCallback requestCallback, object state)
{
return inner.BeginGetClientCertificate(requestCallback, state);
}

public X509Certificate2 EndGetClientCertificate(IAsyncResult asyncResult)
{
return inner.EndGetClientCertificate(asyncResult);
}

public X509Certificate2 GetClientCertificate()
{
return inner.GetClientCertificate();
}

public Task<X509Certificate2> GetClientCertificateAsync()
{
return inner.GetClientCertificateAsync();
}
}
}
122 changes: 122 additions & 0 deletions src/Net/HttpListenerResponseWrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
using System;
using System.IO;
using System.Net;
using System.Text;

namespace Rothko
{
public class HttpListenerResponseWrapper : IHttpListenerResponse
{
private HttpListenerResponse inner;

public HttpListenerResponseWrapper(HttpListenerResponse inner)
{
this.inner = inner;
}

~HttpListenerResponseWrapper()
{
Dispose(false);
}

void IDisposable.Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

public Encoding ContentEncoding
{
get { return inner.ContentEncoding; }
set { inner.ContentEncoding = value; }
}

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

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

public CookieCollection Cookies
{
get { return inner.Cookies; }
set { inner.Cookies = value; }
}

public WebHeaderCollection Headers
{
get { return inner.Headers; }
set { inner.Headers = value; }
}

public bool KeepAlive
{
get { return inner.KeepAlive; }
set { inner.KeepAlive = value; }
}

public Stream OutputStream => inner.OutputStream;

public Version ProtocolVersion
{
get { return inner.ProtocolVersion; }
set { inner.ProtocolVersion = value; }
}

public string RedirectLocation
{
get { return inner.RedirectLocation; }
set { inner.RedirectLocation = value; }
}

public bool SendChunked
{
get { return inner.SendChunked; }
set { inner.SendChunked = value; }
}

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

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

public void Abort() => inner.Abort();

public void AddHeader(string name, string value) => inner.AddHeader(name, value);

public void AppendCookie(Cookie cookie) => inner.AppendCookie(cookie);

public void AppendHeader(string name, string value) => inner.AppendHeader(name, value);

public void Close() => inner.Close();

public void Close(byte[] responseEntity, bool willBlock) => inner.Close(responseEntity, willBlock);

public void CopyFrom(HttpListenerResponse templateResponse) => inner.CopyFrom(templateResponse);

public void Redirect(string url) => inner.Redirect(url);

public void SetCookie(Cookie cookie) => inner.SetCookie(cookie);

protected virtual void Dispose(bool disposing)
{
if (disposing)
{
((IDisposable)inner).Dispose();
}
}
}
}
90 changes: 90 additions & 0 deletions src/Net/HttpListenerWrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Security.Authentication.ExtendedProtection;
using System.Threading.Tasks;

namespace Rothko
{
public sealed class HttpListenerWrapper : IHttpListener
{
readonly HttpListener inner;

public HttpListenerWrapper(HttpListener inner)
{
this.inner = inner;
}

public AuthenticationSchemes AuthenticationSchemes
{
get { return inner.AuthenticationSchemes; }
set { inner.AuthenticationSchemes = value; }
}

public AuthenticationSchemeSelector AuthenticationSchemeSelectorDelegate
{
get { return inner.AuthenticationSchemeSelectorDelegate; }
set { inner.AuthenticationSchemeSelectorDelegate = value; }
}

public ServiceNameCollection DefaultServiceNames => inner.DefaultServiceNames;

public ExtendedProtectionPolicy ExtendedProtectionPolicy
{
get { return inner.ExtendedProtectionPolicy; }
set { inner.ExtendedProtectionPolicy = value; }
}

public HttpListener.ExtendedProtectionSelector ExtendedProtectionSelectorDelegate
{
get { return inner.ExtendedProtectionSelectorDelegate; }
set { inner.ExtendedProtectionSelectorDelegate = value; }
}

public bool IgnoreWriteExceptions
{
get { return inner.IgnoreWriteExceptions; }
set { inner.IgnoreWriteExceptions = value; }
}

public bool IsListening => inner.IsListening;

public ICollection<string> Prefixes => inner.Prefixes;

public string Realm
{
get { return inner.Realm; }
set { inner.Realm = value; }
}

public HttpListenerTimeoutManager TimeoutManager => inner.TimeoutManager;

public bool UnsafeConnectionNtlmAuthentication
{
get { return inner.UnsafeConnectionNtlmAuthentication; }
set { inner.UnsafeConnectionNtlmAuthentication = value; }
}

public void Abort() => inner.Abort();
public IAsyncResult BeginGetContext(AsyncCallback callback, object state) => inner.BeginGetContext(callback, state);
public void Close() => inner.Close();

public IHttpListenerContext EndGetContext(IAsyncResult asyncResult)
{
return new HttpListenerContextWrapper(inner.EndGetContext(asyncResult));
}

public IHttpListenerContext GetContext()
{
return new HttpListenerContextWrapper(inner.GetContext());
}

public async Task<IHttpListenerContext> GetContextAsync()
{
return new HttpListenerContextWrapper(await inner.GetContextAsync());
}

public void Start() => inner.Start();
public void Stop() => inner.Stop();
}
}
Loading

0 comments on commit 9fd2de6

Please sign in to comment.