├── src
└── SharpReverseProxy
│ ├── ProxyStatus.cs
│ ├── ProxyResult.cs
│ ├── ProxyRule.cs
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── ProxyOptions.cs
│ ├── ProxyServerExtension.cs
│ ├── ProxyResultBuilder.cs
│ ├── SharpReverseProxy.csproj
│ └── ProxyMiddleware.cs
├── samples
├── SampleApi1
│ ├── appsettings.json
│ ├── web.config
│ ├── Program.cs
│ ├── Properties
│ │ └── launchSettings.json
│ ├── Controllers
│ │ └── ValuesController.cs
│ ├── SampleApi1.csproj
│ └── Startup.cs
├── SampleApi2
│ ├── appsettings.json
│ ├── web.config
│ ├── Program.cs
│ ├── Properties
│ │ └── launchSettings.json
│ ├── Controllers
│ │ └── ValuesController.cs
│ ├── SampleApi2.csproj
│ └── Startup.cs
├── SampleApiAuthentication
│ ├── appsettings.json
│ ├── Authentication
│ │ ├── TokenOptions.cs
│ │ └── TokenProviderService.cs
│ ├── web.config
│ ├── Program.cs
│ ├── Properties
│ │ └── launchSettings.json
│ ├── SampleApiAuthentication.csproj
│ ├── Controllers
│ │ └── AuthenticationController.cs
│ └── Startup.cs
└── SampleWeb
│ ├── web.config
│ ├── Program.cs
│ ├── Properties
│ └── launchSettings.json
│ ├── SampleWeb.csproj
│ ├── Authentication
│ └── CustomJwtDataFormat.cs
│ └── Startup.cs
├── test
└── SharpReverseProxy.Tests
│ ├── HttpContextFakes
│ ├── FakeHttpMessageHandler.cs
│ ├── HttpContextFake.cs
│ ├── HttpResponseFake.cs
│ ├── HttpRequestFake.cs
│ └── HeaderDictionaryFake.cs
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── SharpReverseProxy.Tests.csproj
│ └── ProxyTests.cs
├── LICENSE
├── SharpReverseProxy.sln
├── .gitignore
└── README.md
/src/SharpReverseProxy/ProxyStatus.cs:
--------------------------------------------------------------------------------
1 | namespace SharpReverseProxy {
2 | public enum ProxyStatus {
3 | NotProxied,
4 | Proxied,
5 | NotAuthenticated
6 | }
7 | }
--------------------------------------------------------------------------------
/samples/SampleApi1/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "IncludeScopes": false,
4 | "LogLevel": {
5 | "Default": "Debug",
6 | "System": "Information",
7 | "Microsoft": "Information"
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/SampleApi2/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "IncludeScopes": false,
4 | "LogLevel": {
5 | "Default": "Debug",
6 | "System": "Information",
7 | "Microsoft": "Information"
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/SampleApiAuthentication/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "IncludeScopes": false,
4 | "LogLevel": {
5 | "Default": "Debug",
6 | "System": "Information",
7 | "Microsoft": "Information"
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/SampleApiAuthentication/Authentication/TokenOptions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace SampleApiAuthentication.Authentication {
4 | public class TokenOptions {
5 | public string Issuer { get; set; } = "Application";
6 | public string Audience { get; set; } = "DefaultClient";
7 | public TimeSpan Expiration { get; set; } = TimeSpan.FromMinutes(15);
8 | }
9 | }
--------------------------------------------------------------------------------
/samples/SampleApi1/web.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/samples/SampleApi2/web.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/samples/SampleWeb/web.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/SharpReverseProxy/ProxyResult.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Net;
3 |
4 | namespace SharpReverseProxy {
5 | public class ProxyResult {
6 | public ProxyStatus ProxyStatus { get; set; }
7 | public int HttpStatusCode { get; set; }
8 | public Uri OriginalUri { get; set; }
9 | public Uri ProxiedUri { get; set; }
10 | public TimeSpan Elapsed { get; set; }
11 | [Obsolete("Elipsed property is deprecated, please use Elapsed instead.")]
12 | public TimeSpan Elipsed {
13 | get { return Elapsed; }
14 | set { Elapsed = value; }
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/samples/SampleApiAuthentication/web.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/samples/SampleWeb/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Threading.Tasks;
6 | using Microsoft.AspNetCore.Hosting;
7 |
8 | namespace SampleWeb
9 | {
10 | public class Program
11 | {
12 | public static void Main(string[] args)
13 | {
14 | var host = new WebHostBuilder()
15 | .UseKestrel()
16 | .UseContentRoot(Directory.GetCurrentDirectory())
17 | .UseIISIntegration()
18 | .UseStartup()
19 | .Build();
20 |
21 | host.Run();
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/SharpReverseProxy/ProxyRule.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Http;
2 | using System;
3 | using System.Net.Http;
4 | using System.Security.Claims;
5 | using System.Threading.Tasks;
6 |
7 | namespace SharpReverseProxy {
8 | public class ProxyRule {
9 | public Func Matcher { get; set; } = uri => false;
10 | public Action Modifier { get; set; } = (msg, user) => { };
11 | public Func ResponseModifier { get; set; } = null;
12 | public bool PreProcessResponse { get; set; } = true;
13 | public bool RequiresAuthentication { get; set; }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/samples/SampleApiAuthentication/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Threading.Tasks;
6 | using Microsoft.AspNetCore.Hosting;
7 | using Microsoft.AspNetCore.Builder;
8 |
9 | namespace SampleApiAuthentication
10 | {
11 | public class Program
12 | {
13 | public static void Main(string[] args)
14 | {
15 | var host = new WebHostBuilder()
16 | .UseKestrel()
17 | .UseContentRoot(Directory.GetCurrentDirectory())
18 | .UseIISIntegration()
19 | .UseStartup()
20 | .Build();
21 |
22 | host.Run();
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/samples/SampleApi1/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Threading.Tasks;
6 | using Microsoft.AspNetCore.Hosting;
7 | using Microsoft.AspNetCore.Builder;
8 |
9 | namespace SampleApi1
10 | {
11 | public class Program
12 | {
13 | public static void Main(string[] args)
14 | {
15 | var host = new WebHostBuilder()
16 | .UseKestrel()
17 | .UseContentRoot(Directory.GetCurrentDirectory())
18 | .UseIISIntegration()
19 | .UseStartup()
20 | .UseUrls("http://localhost:5001")
21 | .Build();
22 |
23 | host.Run();
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/samples/SampleApi2/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Threading.Tasks;
6 | using Microsoft.AspNetCore.Hosting;
7 | using Microsoft.AspNetCore.Builder;
8 |
9 | namespace SampleApi2
10 | {
11 | public class Program
12 | {
13 | public static void Main(string[] args)
14 | {
15 | var host = new WebHostBuilder()
16 | .UseKestrel()
17 | .UseContentRoot(Directory.GetCurrentDirectory())
18 | .UseIISIntegration()
19 | .UseStartup()
20 | .UseUrls("http://localhost:5002")
21 | .Build();
22 |
23 | host.Run();
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/samples/SampleWeb/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:21233/",
7 | "sslPort": 0
8 | }
9 | },
10 | "profiles": {
11 | "IIS Express": {
12 | "commandName": "IISExpress",
13 | "launchBrowser": true,
14 | "environmentVariables": {
15 | "ASPNETCORE_ENVIRONMENT": "Development"
16 | }
17 | },
18 | "SampleWeb": {
19 | "commandName": "Project",
20 | "launchBrowser": true,
21 | "launchUrl": "http://localhost:5000",
22 | "environmentVariables": {
23 | "ASPNETCORE_ENVIRONMENT": "Development"
24 | }
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/test/SharpReverseProxy.Tests/HttpContextFakes/FakeHttpMessageHandler.cs:
--------------------------------------------------------------------------------
1 | using System.Net;
2 | using System.Net.Http;
3 | using System.Threading;
4 | using System.Threading.Tasks;
5 |
6 | namespace SharpReverseProxy.Tests.HttpContextFakes {
7 | public class FakeHttpMessageHandler : HttpMessageHandler {
8 | public HttpRequestMessage RequestMessage { get; private set; }
9 |
10 | public HttpResponseMessage ResponseMessageToReturn { get; set; } = new HttpResponseMessage(HttpStatusCode.OK);
11 |
12 | protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) {
13 | RequestMessage = request;
14 | return Task.FromResult(ResponseMessageToReturn);
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/samples/SampleApi1/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:5001/",
7 | "sslPort": 0
8 | }
9 | },
10 | "profiles": {
11 | "IIS Express": {
12 | "commandName": "IISExpress",
13 | "launchBrowser": true,
14 | "launchUrl": "api/values",
15 | "environmentVariables": {
16 | "ASPNETCORE_ENVIRONMENT": "Development"
17 | }
18 | },
19 | "SampleApi1": {
20 | "commandName": "Project",
21 | "launchBrowser": true,
22 | "launchUrl": "http://localhost:5000/api/values",
23 | "environmentVariables": {
24 | "ASPNETCORE_ENVIRONMENT": "Development"
25 | }
26 | }
27 | }
28 | }
--------------------------------------------------------------------------------
/samples/SampleApi2/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:21258/",
7 | "sslPort": 0
8 | }
9 | },
10 | "profiles": {
11 | "IIS Express": {
12 | "commandName": "IISExpress",
13 | "launchBrowser": true,
14 | "launchUrl": "api/values",
15 | "environmentVariables": {
16 | "ASPNETCORE_ENVIRONMENT": "Development"
17 | }
18 | },
19 | "SampleApi2": {
20 | "commandName": "Project",
21 | "launchBrowser": true,
22 | "launchUrl": "http://localhost:5000/api/values",
23 | "environmentVariables": {
24 | "ASPNETCORE_ENVIRONMENT": "Development"
25 | }
26 | }
27 | }
28 | }
--------------------------------------------------------------------------------
/samples/SampleApiAuthentication/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:18981/",
7 | "sslPort": 0
8 | }
9 | },
10 | "profiles": {
11 | "IIS Express": {
12 | "commandName": "IISExpress",
13 | "launchBrowser": true,
14 | "launchUrl": "api/values",
15 | "environmentVariables": {
16 | "ASPNETCORE_ENVIRONMENT": "Development"
17 | }
18 | },
19 | "SampleApiAuthentication": {
20 | "commandName": "Project",
21 | "launchBrowser": true,
22 | "launchUrl": "http://localhost:5000/api/values",
23 | "environmentVariables": {
24 | "ASPNETCORE_ENVIRONMENT": "Development"
25 | }
26 | }
27 | }
28 | }
--------------------------------------------------------------------------------
/src/SharpReverseProxy/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyConfiguration("")]
9 | [assembly: AssemblyCompany("")]
10 | [assembly: AssemblyProduct("SharpReverseProxy")]
11 | [assembly: AssemblyTrademark("")]
12 |
13 | // Setting ComVisible to false makes the types in this assembly not visible
14 | // to COM components. If you need to access a type in this assembly from
15 | // COM, set the ComVisible attribute to true on that type.
16 | [assembly: ComVisible(false)]
17 |
18 | // The following GUID is for the ID of the typelib if this project is exposed to COM
19 | [assembly: Guid("9058d441-59f9-43ba-a84a-72e51f78cfe7")]
20 |
--------------------------------------------------------------------------------
/test/SharpReverseProxy.Tests/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyConfiguration("")]
9 | [assembly: AssemblyCompany("")]
10 | [assembly: AssemblyProduct("SharpReverseProxy.Tests")]
11 | [assembly: AssemblyTrademark("")]
12 |
13 | // Setting ComVisible to false makes the types in this assembly not visible
14 | // to COM components. If you need to access a type in this assembly from
15 | // COM, set the ComVisible attribute to true on that type.
16 | [assembly: ComVisible(false)]
17 |
18 | // The following GUID is for the ID of the typelib if this project is exposed to COM
19 | [assembly: Guid("02e9a359-2493-44d0-b136-65254f83153f")]
20 |
--------------------------------------------------------------------------------
/src/SharpReverseProxy/ProxyOptions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Net.Http;
5 |
6 | namespace SharpReverseProxy {
7 | public class ProxyOptions {
8 | public List ProxyRules { get; set; } = new List();
9 | public HttpMessageHandler BackChannelMessageHandler { get; set; }
10 | public Action Reporter { get; set; } = result => { };
11 |
12 | public bool FollowRedirects { get; set; } = true;
13 | public bool AddForwardedHeader { get; set; } = false;
14 |
15 | public ProxyOptions() {}
16 |
17 | public ProxyOptions(List rules, Action reporter = null) {
18 | ProxyRules = rules;
19 | if (reporter != null) {
20 | Reporter = reporter;
21 | }
22 | }
23 |
24 | public void AddProxyRule(ProxyRule rule) {
25 | ProxyRules.Add(rule);
26 | }
27 | }
28 | }
--------------------------------------------------------------------------------
/src/SharpReverseProxy/ProxyServerExtension.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using Microsoft.AspNetCore.Builder;
4 | using Microsoft.Extensions.Options;
5 |
6 | namespace SharpReverseProxy {
7 | public static class ProxyExtension {
8 |
9 | ///
10 | /// Sends request to remote server as specified in options
11 | ///
12 | ///
13 | /// Options and rules for proxy actions
14 | ///
15 | public static IApplicationBuilder UseProxy(this IApplicationBuilder app, ProxyOptions proxyOptions) {
16 | return app.UseMiddleware(Options.Create(proxyOptions));
17 | }
18 |
19 | public static IApplicationBuilder UseProxy(this IApplicationBuilder app, List rules, Action reporter = null) {
20 | return app.UseMiddleware(Options.Create(new ProxyOptions(rules, reporter)));
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/samples/SampleApi1/Controllers/ValuesController.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using Microsoft.AspNetCore.Mvc;
6 |
7 | namespace SampleApi1.Controllers {
8 | [Route("api/[controller]")]
9 | public class ValuesController : Controller {
10 | // GET api/values
11 | [HttpGet]
12 | public IEnumerable Get() {
13 | return new string[] { "api1", "api1" };
14 | }
15 |
16 | // GET api/values/5
17 | [HttpGet("{id}")]
18 | public string Get(int id) {
19 | return "value";
20 | }
21 |
22 | // POST api/values
23 | [HttpPost]
24 | public string Post([FromBody]string value) {
25 | return value;
26 | }
27 |
28 | // PUT api/values/5
29 | [HttpPut("{id}")]
30 | public void Put(int id, [FromBody]string value) {
31 | }
32 |
33 | // DELETE api/values/5
34 | [HttpDelete("{id}")]
35 | public void Delete(int id) {
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 SharpTools
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/samples/SampleApi2/Controllers/ValuesController.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using Microsoft.AspNetCore.Mvc;
6 |
7 | namespace SampleApi2.Controllers
8 | {
9 | [Route("api/[controller]")]
10 | public class ValuesController : Controller
11 | {
12 | // GET api/values
13 | [HttpGet]
14 | public IEnumerable Get()
15 | {
16 | return new string[] { "api2", "value2" };
17 | }
18 |
19 | // GET api/values/5
20 | [HttpGet("{id}")]
21 | public string Get(int id)
22 | {
23 | return "value";
24 | }
25 |
26 | // POST api/values
27 | [HttpPost]
28 | public void Post([FromBody]string value)
29 | {
30 | }
31 |
32 | // PUT api/values/5
33 | [HttpPut("{id}")]
34 | public void Put(int id, [FromBody]string value)
35 | {
36 | }
37 |
38 | // DELETE api/values/5
39 | [HttpDelete("{id}")]
40 | public void Delete(int id)
41 | {
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/SharpReverseProxy/ProxyResultBuilder.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.AspNetCore.Http;
3 |
4 | namespace SharpReverseProxy {
5 | public class ProxyResultBuilder {
6 | private ProxyResult _result;
7 | private DateTime _start;
8 | public ProxyResultBuilder(Uri originalUri) {
9 | _result = new ProxyResult {
10 | OriginalUri = originalUri
11 | };
12 | _start = DateTime.Now;
13 | }
14 |
15 | public ProxyResult Proxied(Uri proxiedUri, int statusCode) {
16 | Finish(ProxyStatus.Proxied);
17 | _result.ProxiedUri = proxiedUri;
18 | _result.HttpStatusCode = statusCode;
19 | return _result;
20 | }
21 |
22 | public ProxyResult NotProxied(int statusCode) {
23 | Finish(ProxyStatus.NotProxied);
24 | _result.HttpStatusCode = statusCode;
25 | return _result;
26 | }
27 |
28 | public ProxyResult NotAuthenticated() {
29 | Finish(ProxyStatus.NotAuthenticated);
30 | _result.HttpStatusCode = StatusCodes.Status401Unauthorized;
31 | return _result;
32 | }
33 |
34 | private ProxyResult Finish(ProxyStatus proxyStatus) {
35 | _result.ProxyStatus = proxyStatus;
36 | _result.Elapsed = DateTime.Now - _start;
37 | return _result;
38 | }
39 | }
40 | }
--------------------------------------------------------------------------------
/samples/SampleWeb/SampleWeb.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp1.1
5 | true
6 | SampleWeb
7 | Exe
8 | SampleWeb
9 | 1.0.4
10 | $(PackageTargetFallback);dotnet5.6;portable-net45+win8
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/test/SharpReverseProxy.Tests/HttpContextFakes/HttpContextFake.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Security.Claims;
4 | using System.Threading;
5 | using Microsoft.AspNetCore.Http;
6 | using Microsoft.AspNetCore.Http.Authentication;
7 | using Microsoft.AspNetCore.Http.Features;
8 |
9 | namespace SharpReverseProxy.Tests.HttpContextFakes {
10 | public class HttpContextFake : HttpContext {
11 | public HttpContextFake(HttpRequestFake request, HttpResponseFake response = null) {
12 | request.SetHttpContext(this);
13 | Request = request;
14 | Response = response ?? new HttpResponseFake();
15 | }
16 |
17 | public override void Abort() {}
18 | public override IFeatureCollection Features { get; }
19 | public override HttpRequest Request { get; }
20 | public override HttpResponse Response { get; }
21 | public override ConnectionInfo Connection { get; }
22 | public override WebSocketManager WebSockets { get; }
23 | public override AuthenticationManager Authentication { get; }
24 | public override ClaimsPrincipal User { get; set; }
25 | public override IDictionary