Skip to content

AspNetCore.Proxy 3.1.0

Compare
Choose a tag to compare
@twitchax twitchax released this 09 Oct 20:33
· 82 commits to master since this release
aa1da30

This release adds a few features.

WebSocket Support

All proxying methods can now also proxy WebSocket requests by specifying a WebSocket endpoint.

app.UseProxy("/ws", "ws://mysite.com/ws");

RunProxy

You can now proxy over all endpoints.

app.RunProxy(context =>
{
    if(context.WebSockets.IsWebSocketRequest)
        return "wss://mysite.com/ws";

    return "https://mysite.com";
});

Custom HttpClient

Via AddProxies.

services.AddProxies(client => client.Timeout = TimeSpan.FromSeconds(10));

Via ProxyOptions.

this.ProxyAsync(
    $"https://jsonplaceholder.typicode.com/posts/{postId}",
    ProxyOptions.Instance.WithHttpClientName("CustomClient"));

Intercept Method

You can now intercept a proxy request in certain circumstances.

var options = ProxyOptions.Instance
    .WithIntercept(async context =>
    {
        if(c.Connection.RemotePort == 7777)
        {
            c.Response.StatusCode = 300;
            await c.Response.WriteAsync("I don't like this port, so I am not proxying this request!");
            return true;
        }

        return false;
    });

return this.ProxyAsync($"https://mysite.com", options);