Skip to content

Commit

Permalink
Introduce router for reverse proxy which seems more reasonable.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaliumhexacyanoferrat committed Jan 20, 2020
1 parent 63c80bb commit 7ab39f5
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using System;

using GenHTTP.Api.Infrastructure;
using GenHTTP.Api.Modules;

using GenHTTP.Api.Routing;
using GenHTTP.Modules.Core.General;

namespace GenHTTP.Modules.Core.Proxy
{

public class ReverseProxyProviderBuilder : ContentBuilderBase
public class ReverseProxyBuilder : RouterBuilderBase<ReverseProxyRouter>
{
private string? _Upstream;

Expand All @@ -17,7 +16,7 @@ public class ReverseProxyProviderBuilder : ContentBuilderBase

#region Functionality

public ReverseProxyProviderBuilder Upstream(string upstream)
public ReverseProxyBuilder Upstream(string upstream)
{
_Upstream = upstream;

Expand All @@ -29,26 +28,26 @@ public ReverseProxyProviderBuilder Upstream(string upstream)
return this;
}

public ReverseProxyProviderBuilder ConnectTimeout(TimeSpan connectTimeout)
public ReverseProxyBuilder ConnectTimeout(TimeSpan connectTimeout)
{
_ConnectTimeout = connectTimeout;
return this;
}

public ReverseProxyProviderBuilder ReadTimeout(TimeSpan readTimeout)
public ReverseProxyBuilder ReadTimeout(TimeSpan readTimeout)
{
_ReadTimeout = readTimeout;
return this;
}

public override IContentProvider Build()
public override IRouter Build()
{
if (_Upstream == null)
{
throw new BuilderMissingPropertyException("Upstream");
}

return new ReverseProxyProvider(_Upstream, _ConnectTimeout, _ReadTimeout, _Modification);
return new ReverseProxyRouter(_Upstream, _ConnectTimeout, _ReadTimeout, _ErrorHandler);
}

#endregion
Expand Down
46 changes: 46 additions & 0 deletions Modules/GenHTTP.Modules.Core/Proxy/ReverseProxyRouter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;

using GenHTTP.Api.Modules;
using GenHTTP.Api.Protocol;
using GenHTTP.Api.Routing;
using GenHTTP.Modules.Core.General;

namespace GenHTTP.Modules.Core.Proxy
{

public class ReverseProxyRouter : RouterBase, IRouter
{

#region Get-/Setters

private ReverseProxyProvider Provider { get; }

#endregion

#region Initialization

public ReverseProxyRouter(string upstream, TimeSpan connectTimeout, TimeSpan readTimeout, IContentProvider? errorHandler) : base(null, errorHandler)
{
Provider = new ReverseProxyProvider(upstream, connectTimeout, readTimeout, null);
}

#endregion

#region Functionality

public override IEnumerable<ContentElement> GetContent(IRequest request, string basePath) => new List<ContentElement>();

public override void HandleContext(IEditableRoutingContext current)
{
current.RegisterContent(Provider);
current.Scope(this);
}

public override string? Route(string path, int currentDepth) => Parent.Route(path, currentDepth);

#endregion

}

}
4 changes: 2 additions & 2 deletions Modules/GenHTTP.Modules.Core/ReverseProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace GenHTTP.Modules.Core
public static class ReverseProxy
{

public static ReverseProxyProviderBuilder Create()
public static ReverseProxyBuilder Create()
{
return new ReverseProxyProviderBuilder();
return new ReverseProxyBuilder();
}

}
Expand Down

0 comments on commit 7ab39f5

Please sign in to comment.