Skip to content

babizhu/ReverseProxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ReverseProxy

反向代理服务器,企图比拼nginx的反向代理功能

用法

  • 修改uri
val bootstrap = DefaultReverseProxyServer.bootstrap()
            .withPort(8000)
            .withHttpFilter(object : HttpFilterAdapter(){
                override fun clientToProxyRequest(httpObject: HttpObject): HttpResponse? {
                    if (httpObject is HttpRequest) {
                        httpObject.uri = "/test"//修改uri
                    }
                    return null
                }
            })
bootstrap.start()
    
  • ip黑名单
val bootstrap = DefaultReverseProxyServer.bootstrap()
            .withPort(8000)
            .withHttpFilter(BlackListFilter())
bootstrap.start()
    
  • 采用ip hash 进行轮询
val bootstrap = DefaultReverseProxyServer.bootstrap()
            .withRoutePolice(IpHashPolicy())
            .withPort(8000)
bootstrap.start()
  • 根据uri进行路由
val bootstrap = DefaultReverseProxyServer.bootstrap()
            .withRoutePolice(object : RoutePolicy {
                override fun getBackendServerAddress(request: HttpRequest, channel: Channel): InetSocketAddress? {
                    return when (request.uri()) {
                        "user" -> InetSocketAddress("user.api.com", 80)
                        "prouduct" -> InetSocketAddress("product.api.com", 80)
                        else -> InetSocketAddress("else.api.com", 80)
                    }
                }
            })
            .withPort(8000)
            .withHttpFilter(BlackListFilter())
    bootstrap.start()

性能

请点击 .

About

反向代理服务器,企图比拼nginx

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages