Coder Social home page Coder Social logo

httpmouse's Introduction

HttpMouse

基于yarp的http公网反向代理到内网的服务端与客户端库

Nuget

包名 描述 Nuget
HttpMouse 服务端用 NuGet
HttpMouse.Client 客户端用 NuGet

原理图

image

服务端开发

基础入门

/// <summary>
/// 配置服务
/// </summary>
/// <param name="services"></param>
public void ConfigureServices(IServiceCollection services)
{
    services.AddHttpMouse(options =>
    {
        options.DefaultKey = "客户端连接秘钥";
    });
}

/// <summary>
/// 配置中间件
/// </summary>
/// <param name="app"></param>
/// <param name="hostEnvironment"></param>
public void Configure(IApplicationBuilder app, IHostEnvironment hostEnvironment)
{
    app.UseHttpMouse();
    app.UseRouting();

    // 其它中间件

    app.UseEndpoints(endpoints =>
    {
        endpoints.MapReverseProxy();
    });
} 

自定义客户端认证

/// <summary>
/// 配置服务
/// </summary>
/// <param name="services"></param>
public void ConfigureServices(IServiceCollection services)
{
    services.AddHttpMouse(options =>
    {
        options.DefaultKey = "客户端连接秘钥";
    });

    services.AddSingleton<IHttpMouseClientVerifier, ComstomClientVerifier>();
}
class ComstomClientVerifier : IHttpMouseClientVerifier
{
    public ValueTask<bool> VerifyAsync(IHttpMouseClient httpMouseClient)
    {
        var key = httpMouseClient.Key;
        var domain = httpMouseClient.Domain;

        var result = false;
        if (domain == "b.xx.com")
        {
            result = key == "123456";
        }

        return ValueTask.FromResult(result);
    }
}

YARP功能

services.AddHttpMouse()返回YARP的IReverseProxyBuilder对象,此对象还有其它比较重要的功能。有关YARP的完整功能介绍,可以阅读YARP文档

AddConfigFilter

AddConfigFilter()实际注册了一个IProxyConfigFilter服务,服务用于修改既有的路由与集群配置。

AddTransforms

AddTransforms()提供多个重载方法,最终注册ITransformProvider服务,服务用于变换http请求或响应内容。

ConfigureHttpClient

用于配置SocketsHttpHandler的配置

LoadFromConfig

LoadFromConfig()实际是注册了基于配置文件的IProxyConfigProvider,HttpMouse实现了基于内存的IProxyConfigProvider,功能冲突,不能调用此方法

httpmouse's People

Contributors

xljiulang avatar

Stargazers

 avatar  avatar zhonghy avatar  avatar  avatar  avatar LAW avatar Joe Du avatar viacooky avatar well.james avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.