go>> mps>> 返回
项目作者: telanflow

项目描述 :
MPS is a high-performance HTTP(S) proxy library that supports forward proxies, reverse proxies, man-in-the-middle proxies, tunnel proxies, Websocket proxies. MPS 是一个高性能HTTP(s)中间代理库,它支持正向代理、反向代理、中间人代理、隧道代理、Websocket代理
高级语言: Go
项目地址: git://github.com/telanflow/mps.git
创建时间: 2020-07-31T03:58:43Z
项目社区:https://github.com/telanflow/mps

开源协议:BSD 3-Clause "New" or "Revised" License

下载




MPS

English | 🇨🇳中文

📖 Introduction

MPS
stars
GitHub release (latest SemVer)
GitHub go.mod Go version
license

MPS (middle-proxy-server) is an high-performance middle proxy library. support HTTP, HTTPS, Websocket, ForwardProxy, ReverseProxy, TunnelProxy, MitmProxy.

🚀 Features

  • [X] Http Proxy
  • [X] Https Proxy
  • [X] Forward Proxy
  • [X] Reverse Proxy
  • [X] Tunnel Proxy
  • [X] Mitm Proxy (Man-in-the-middle)
  • [X] WekSocket Proxy

🧰 Install

  1. go get -u github.com/telanflow/mps

🛠 How to use

A simple proxy service

  1. package main
  2. import (
  3. "github.com/telanflow/mps"
  4. "log"
  5. "net/http"
  6. )
  7. func main() {
  8. proxy := mps.NewHttpProxy()
  9. log.Fatal(http.ListenAndServe(":8080", proxy))
  10. }

More examples

🧬 Middleware

Middleware can intercept requests and responses.
we have several middleware implementations built in, including BasicAuth

  1. func main() {
  2. proxy := mps.NewHttpProxy()
  3. proxy.Use(mps.MiddlewareFunc(func(req *http.Request, ctx *mps.Context) (*http.Response, error) {
  4. log.Printf("[INFO] middleware -- %s %s", req.Method, req.URL)
  5. return ctx.Next(req)
  6. }))
  7. proxy.UseFunc(func(req *http.Request, ctx *mps.Context) (*http.Response, error) {
  8. log.Printf("[INFO] middleware -- %s %s", req.Method, req.URL)
  9. resp, err := ctx.Next(req)
  10. if err != nil {
  11. return nil, err
  12. }
  13. log.Printf("[INFO] resp -- %d", resp.StatusCode)
  14. return resp, err
  15. })
  16. log.Fatal(http.ListenAndServe(":8080", proxy))
  17. }

♻️ Filters

Filters can filter requests and responses for unified processing.
It is based on middleware implementation.

  1. func main() {
  2. proxy := mps.NewHttpProxy()
  3. // request Filter Group
  4. reqGroup := proxy.OnRequest(mps.FilterHostMatches(regexp.MustCompile("^.*$")))
  5. reqGroup.DoFunc(func(req *http.Request, ctx *mps.Context) (*http.Request, *http.Response) {
  6. log.Printf("[INFO] req -- %s %s", req.Method, req.URL)
  7. return req, nil
  8. })
  9. // response Filter Group
  10. respGroup := proxy.OnResponse()
  11. respGroup.DoFunc(func(resp *http.Response, err error, ctx *mps.Context) (*http.Response, error) {
  12. if err != nil {
  13. log.Printf("[ERRO] resp -- %s %v", ctx.Request.Method, err)
  14. return nil, err
  15. }
  16. log.Printf("[INFO] resp -- %d", resp.StatusCode)
  17. return resp, err
  18. })
  19. log.Fatal(http.ListenAndServe(":8080", proxy))
  20. }

📄 License

Source code in MPS is available under the BSD 3 License.