Documentation ¶
Index ¶
- Constants
- Variables
- func CloseConnection()
- func ConvertToDbKey(key string) string
- func CopyFile(src, dst string) (int64, error)
- func CopyResponseHeader(w http.ResponseWriter, res *http.Response)
- func ExecCommand(command string) (string, bool)
- func FillReqLogResponse(reqLog *ReqLog[Message], res *http.Response)
- func FilterFormType(s []byte) []byte
- func FindReplaceByRegexp(proxyReq http.Request) (*url.URL, string)
- func FmtDuration(d time.Duration) string
- func GenCertificate() (cert tls.Certificate, err error)
- func Go(act func())
- func HandleCompressed(msg *Message, encoding string)
- func HandleRespError(w http.ResponseWriter, r *http.Request, err error, reqLog *ReqLog[Message], ...)
- func HttpProxy()
- func InitConfig()
- func InitConnection()
- func InitRedisConn(redisConf *RedisConf)
- func IsJsonResponse(header http.Header) bool
- func IsMatch(pattern, fullUrl string) bool
- func IsValidConnection(client *redis.Client) bool
- func Json[T any](serviceFunc func(request *http.Request) T) http.HandlerFunc
- func MarkGuiMode()
- func MatchNeedStorage(proxyReq http.Request, proxyType string) bool
- func ProxyHandler(w http.ResponseWriter, r *http.Request)
- func ReloadConfByCacheObj()
- func RemoveReqMember(member any)
- func RemoveReqUrlKey(key string)
- func RspStr(writer http.ResponseWriter, val string)
- func SaveAs(src, suffix string, newContent []byte) error
- func SaveReqLog(log *ReqLog[Message])
- func StartAndCloseHook(server *http.Server, fns ...func() error)
- func StartLog(mode string)
- func StoreByMemory(conf *ProxyConf)
- func TrySaveLog(reqLog *ReqLog[Message], res *http.Response)
- func Watch(fns ...func() error)
- func WriteJsonError(writer http.ResponseWriter, code int, msg string)
- func WriteJsonParamError(writer http.ResponseWriter, msg string)
- func WriteJsonRsp(writer http.ResponseWriter, val any)
- type Message
- type MessageVO
- type ProxyConf
- type ProxyGroup
- type ProxyRouter
- type ProxySelf
- type ProxySwitch
- type RedisConf
- type ReqLog
- func ConvertLog(v *ReqLog[Message]) *ReqLog[MessageVO]
- func GetDetailByKey(key string) *ReqLog[Message]
- func MatchDetailByKeyAndKwd(key, kwd string) *ReqLog[Message]
- func QueryLogDetail(keyList []string) []*ReqLog[Message]
- func RewriteRequestAndBuildLog(newUrl *url.URL, proxyReq *http.Request, needStorage bool) (string, *ReqLog[Message])
Constants ¶
View Source
const ( Open = 1 // 开启配置 Close = 0 // 关闭配置 Direct = "DIRECT" // 直连 Modify = "MOD" // 抓包并修改 Proxy = "PROXY" // 抓包代理 // PacUrl https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Proxy_servers_and_tunneling/Proxy_Auto-Configuration_PAC_file PacUrl = "/pac" // pac url HeaderProxyBench = "Proxybench" )
View Source
const ( PoolSize = 5 Prefix = "proxy" )
Variables ¶
View Source
var ( Port int ApiPort int ReloadConf bool TrackAllType bool Debug bool BuildVersion string HttpMode bool JsonPath string PacPath string ID string )
View Source
var ( ProxyConfVar *ProxyConf ConfigReload = make(chan bool, 1) // DirectContentType https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type // https://tool.oschina.net/commons/_contenttype.dea DirectContentType = []string{"javascript", "css", "image/", "pdf", "msword", "octet-stream", "audio", "video"} StaticUrlPattern = ".*((js)|(css)|(html))$" )
View Source
var ( Conn *redis.Client Leveldb *leveldb.DB RequestList = "" // ZSet redis key (member: 03-16 18:27:45.653 80b85e3c653, score: request nanoTime), leveldb key (80b85e3c653) RequestUrlList = "" // Hash: id <-> url )
View Source
var HelpInfo = ctool.HelpInfo{ Description: "Http proxy for reroute and trace", BuildVersion: BuildVersion, Version: "1.0.4", Flags: []ctool.ParamVO{ {Short: "-r", BoolVar: &ReloadConf, Comment: "auto reload changed config"}, {Short: "-d", BoolVar: &Debug, Comment: "debug mode"}, {Short: "-x", BoolVar: &HttpMode, Comment: "track or modify http, capture https. (default https mode, need install cert)"}, {Short: "-A", BoolVar: &TrackAllType, Comment: "track all request default track json type request"}, }, Options: []ctool.ParamVO{ {Short: "-p", IntVar: &Port, Int: 1234, Value: "port", Comment: "proxy port"}, {Short: "-w", IntVar: &ApiPort, Int: 1235, Value: "port", Comment: "web api port"}, {Short: "-j", StringVar: &JsonPath, String: "", Value: "path", Comment: "json config file abs path"}, {Short: "-a", StringVar: &PacPath, String: "", Value: "path", Comment: "pac file abs path"}, {Short: "-i", StringVar: &ID, String: "", Value: "id", Comment: "param id over json id"}, }, }
View Source
var (
PacFilePath = "/.dev-proxy/dev-proxy.pac"
)
Functions ¶
func CloseConnection ¶
func CloseConnection()
func ConvertToDbKey ¶
func CopyResponseHeader ¶
func CopyResponseHeader(w http.ResponseWriter, res *http.Response)
func ExecCommand ¶
func FmtDuration ¶
func GenCertificate ¶
func GenCertificate() (cert tls.Certificate, err error)
https://mojotv.cn/2018/12/26/how-to-create-a-https-proxy-service-in-100-lines-of-code https://github.com/golang/go/issues/46319 https://github.com/Zartenc/httpsproxy.git
func HandleCompressed ¶
func HandleRespError ¶
func InitConfig ¶
func InitConfig()
func InitConnection ¶
func InitConnection()
func InitRedisConn ¶
func InitRedisConn(redisConf *RedisConf)
func IsJsonResponse ¶
func IsValidConnection ¶
func MarkGuiMode ¶
func MarkGuiMode()
func ProxyHandler ¶
func ProxyHandler(w http.ResponseWriter, r *http.Request)
func ReloadConfByCacheObj ¶
func ReloadConfByCacheObj()
func RemoveReqMember ¶
func RemoveReqMember(member any)
func RemoveReqUrlKey ¶
func RemoveReqUrlKey(key string)
func RspStr ¶
func RspStr(writer http.ResponseWriter, val string)
func SaveReqLog ¶
func StartAndCloseHook ¶
func StoreByMemory ¶
func StoreByMemory(conf *ProxyConf)
func TrySaveLog ¶
TrySaveLog 尝试保存,忽略静态资源及无类型标记的接口
func WriteJsonError ¶
func WriteJsonError(writer http.ResponseWriter, code int, msg string)
func WriteJsonParamError ¶
func WriteJsonParamError(writer http.ResponseWriter, msg string)
func WriteJsonRsp ¶
func WriteJsonRsp(writer http.ResponseWriter, val any)
Types ¶
type MessageVO ¶
type MessageVO struct { Header http.Header `json:"header"` Body any `json:"body"` BodyStr *string `json:"bodyStr,omitempty"` }
MessageVO use in rest api
type ProxyConf ¶
type ProxyConf struct { Id string `json:"id"` Redis *RedisConf `json:"redis"` Groups []*ProxyGroup `json:"groups"` ProxySelf *ProxySelf `json:"proxy"` // 抓包 ProxyDirect *ProxySelf `json:"direct"` // 不抓包,不存储 }
type ProxyGroup ¶
type ProxyGroup struct { Name string `json:"name"` ProxyType int `json:"proxy_type"` Routers []ProxyRouter `json:"routers"` }
func (*ProxyGroup) GetName ¶
func (p *ProxyGroup) GetName() string
func (*ProxyGroup) HasUse ¶
func (g *ProxyGroup) HasUse() bool
func (*ProxyGroup) SwitchUse ¶
func (g *ProxyGroup) SwitchUse()
type ProxyRouter ¶
type ProxySelf ¶
type ProxySwitch ¶
type ReqLog ¶
type ReqLog[T any] struct { Id string `json:"id"` CacheId string `json:"cacheId"` Method string `json:"method"` Url string `json:"url"` Status string `json:"status"` StatusCode int `json:"statusCode"` ReqTime time.Time `json:"reqTime"` ResTime time.Time `json:"resTime"` ElapsedTime string `json:"useTime"` Request T `json:"request"` Response T `json:"response"` }
func GetDetailByKey ¶
func MatchDetailByKeyAndKwd ¶
MatchDetailByKeyAndKwd key: redis key kwd: 搜索关键字 (url 以及header等所有字符串)
func QueryLogDetail ¶
Click to show internal directories.
Click to hide internal directories.