<commit_before>SharpReverseProxy
=================

Powerful Reverse Proxy written as OWIN Middleware. Perfect for ASP .NET, Web API, microservices, and more.

Looking for a way to build an API Gateway based on rules, I found the [Asp.Net Proxy repository](https://github.com/aspnet/Proxy).

The problem is that it proxies all request and I would like to have granular control of the proxy rules. So I wrote SharpReverseProxy. 😃

## How to Use

Install the [SharpReverseProxy package](https://www.nuget.org/packages/SharpReverseProxy/) via Nuget:

```powershell
Install-Package SharpReverseProxy
```

Open your *Startup.cs* and configure your reverse proxy:

```csharp
public void Configure(IApplicationBuilder app, 
		  IHostingEnvironment env, 
		  ILoggerFactory loggerFactory) {

    app.UseProxy(new List<ProxyRule> {
	new ProxyRule {
	     Matcher = uri => uri.AbsoluteUri.Contains("/api/"),
	     Modifier = uri => {
		 var match = Regex.Match(uri.Path, "/api/(.+)service");
		 uri.Host = match.Groups[1].Value + "." + uri.Host;
		 uri.Path = uri.Path.Replace(match.Value, "/api/");
	     },
	    RequiresAuthentication = true
	}
    },
    r => {
	_logger.LogDebug($"Proxy: {r.ProxyStatus} Url: {r.OriginalUri} Time: {r.Elipsed}");
	if (r.ProxyStatus == ProxyStatus.Proxied) {
	    _logger.LogDebug($"        New Url: {r.ProxiedUri.AbsoluteUri} Status: {r.HttpStatusCode}");
	}
    });
}
```

### Explanation:

Add a proxy rule. You can create as many as you want and the proxy will use the first matched rule to divert the request.<commit_msg>Update example in README.md to reflect current API<commit_after>SharpReverseProxy
=================

Powerful Reverse Proxy written as OWIN Middleware. Perfect for ASP .NET, Web API, microservices, and more.

Looking for a way to build an API Gateway based on rules, I found the [Asp.Net Proxy repository](https://github.com/aspnet/Proxy).

The problem is that it proxies all request and I would like to have granular control of the proxy rules. So I wrote SharpReverseProxy. 😃

## How to Use

Install the [SharpReverseProxy package](https://www.nuget.org/packages/SharpReverseProxy/) via Nuget:

```powershell
Install-Package SharpReverseProxy
```

Open your *Startup.cs* and configure your reverse proxy:

```csharp
public void Configure(IApplicationBuilder app, 
		  IHostingEnvironment env, 
		  ILoggerFactory loggerFactory) {

    app.UseProxy(new List<ProxyRule> {
	new ProxyRule {
	     Matcher = uri => uri.AbsoluteUri.Contains("/api/"),
	     Modifier = (req, user) => {
		var match = Regex.Match(req.RequestUri.AbsolutePath, "/api/(.+)service");
		req.RequestUri = new Uri(string.Format("http://{0}.{1}/{2}",
		    match.Groups[1].Value,
		    req.RequestUri.Host,
		    req.RequestUri.AbsolutePath.Replace(match.Value, "/api/")
		));
	     },
	    RequiresAuthentication = true
	}
    },
    r => {
	_logger.LogDebug($"Proxy: {r.ProxyStatus} Url: {r.OriginalUri} Time: {r.Elipsed}");
	if (r.ProxyStatus == ProxyStatus.Proxied) {
	    _logger.LogDebug($"        New Url: {r.ProxiedUri.AbsoluteUri} Status: {r.HttpStatusCode}");
	}
    });
}
```

### Explanation:

Add a proxy rule. You can create as many as you want and the proxy will use the first matched rule to divert the request.
{'fraction_non_alphanumeric': 0.13177339901477833, 'fraction_numerical': 0.001539408866995074, 'mean_word_length': 3.842026825633383, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6009610', 'n_tokens_mistral': 1093, 'n_tokens_neox': 999, 'n_words': 312}