{"id":13481595,"url":"https://github.com/go-httpproxy/httpproxy","last_synced_at":"2025-03-27T12:31:11.222Z","repository":{"id":37359331,"uuid":"119390933","full_name":"go-httpproxy/httpproxy","owner":"go-httpproxy","description":"Go HTTP proxy server library","archived":false,"fork":false,"pushed_at":"2022-06-02T13:34:46.000Z","size":118,"stargazers_count":215,"open_issues_count":10,"forks_count":58,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-08-01T17:29:23.729Z","etag":null,"topics":["go","golang","http-proxy","proxy","proxy-server","web-proxy"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/go-httpproxy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-29T14:09:51.000Z","updated_at":"2024-06-04T01:29:28.000Z","dependencies_parsed_at":"2022-07-12T22:30:30.655Z","dependency_job_id":null,"html_url":"https://github.com/go-httpproxy/httpproxy","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-httpproxy%2Fhttpproxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-httpproxy%2Fhttpproxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-httpproxy%2Fhttpproxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-httpproxy%2Fhttpproxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/go-httpproxy","download_url":"https://codeload.github.com/go-httpproxy/httpproxy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222251760,"owners_count":16955894,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","http-proxy","proxy","proxy-server","web-proxy"],"created_at":"2024-07-31T17:00:53.179Z","updated_at":"2024-10-30T15:31:08.666Z","avatar_url":"https://github.com/go-httpproxy.png","language":"Go","readme":"# Go HTTP proxy server library\n\n[![GoDoc](https://godoc.org/github.com/go-httpproxy/httpproxy?status.svg)](https://godoc.org/github.com/go-httpproxy/httpproxy)\n\nPackage httpproxy provides a customizable HTTP proxy; supports HTTP, HTTPS through\nCONNECT. And also provides HTTPS connection using \"Man in the Middle\" style\nattack.\n\nIt's easy to use. `httpproxy.Proxy` implements `Handler` interface of `net/http`\npackage to offer `http.ListenAndServe` function.\n\n## Installing\n\n```sh\ngo get -u github.com/go-httpproxy/httpproxy\n# or\ngo get -u gopkg.in/httpproxy.v1\n```\n\n## Usage\n\nLibrary has two significant structs: Proxy and Context.\n\n### Proxy struct\n\n```go\n// Proxy defines parameters for running an HTTP Proxy. It implements\n// http.Handler interface for ListenAndServe function. If you need, you must\n// set Proxy struct before handling requests.\ntype Proxy struct {\n\t// Session number of last proxy request.\n\tSessionNo int64\n\n\t// RoundTripper interface to obtain remote response.\n\t// By default, it uses \u0026http.Transport{}.\n\tRt http.RoundTripper\n\n\t// Certificate key pair.\n\tCa tls.Certificate\n\n\t// User data to use free.\n\tUserData interface{}\n\n\t// Error callback.\n\tOnError func(ctx *Context, where string, err *Error, opErr error)\n\n\t// Accept callback. It greets proxy request like ServeHTTP function of\n\t// http.Handler.\n\t// If it returns true, stops processing proxy request.\n\tOnAccept func(ctx *Context, w http.ResponseWriter, r *http.Request) bool\n\n\t// Auth callback. If you need authentication, set this callback.\n\t// If it returns true, authentication succeeded.\n\tOnAuth func(ctx *Context, authType string, user string, pass string) bool\n\n\t// Connect callback. It sets connect action and new host.\n\t// If len(newhost) \u003e 0, host changes.\n\tOnConnect func(ctx *Context, host string) (ConnectAction ConnectAction,\n\t\tnewHost string)\n\n\t// Request callback. It greets remote request.\n\t// If it returns non-nil response, stops processing remote request.\n\tOnRequest func(ctx *Context, req *http.Request) (resp *http.Response)\n\n\t// Response callback. It greets remote response.\n\t// Remote response sends after this callback.\n\tOnResponse func(ctx *Context, req *http.Request, resp *http.Response)\n\n\t// If ConnectAction is ConnectMitm, it sets chunked to Transfer-Encoding.\n\t// By default, true.\n\tMitmChunked bool\n\n\t// HTTP Authentication type. If it's not specified (\"\"), uses \"Basic\".\n\t// By default, \"\".\n\tAuthType string\n}\n```\n\n### Context struct\n\n```go\n// Context keeps context of each proxy request.\ntype Context struct {\n\t// Pointer of Proxy struct handled this context.\n\t// It's using internally. Don't change in Context struct!\n\tPrx *Proxy\n\n\t// Session number of this context obtained from Proxy struct.\n\tSessionNo int64\n\n\t// Sub session number of processing remote connection.\n\tSubSessionNo int64\n\n\t// Original Proxy request.\n\t// It's using internally. Don't change in Context struct!\n\tReq *http.Request\n\n\t// Original Proxy request, if proxy request method is CONNECT.\n\t// It's using internally. Don't change in Context struct!\n\tConnectReq *http.Request\n\n\t// Action of after the CONNECT, if proxy request method is CONNECT.\n\t// It's using internally. Don't change in Context struct!\n\tConnectAction ConnectAction\n\n\t// Remote host, if proxy request method is CONNECT.\n\t// It's using internally. Don't change in Context struct!\n\tConnectHost string\n\n\t// User data to use free.\n\tUserData interface{}\n}\n```\n\n## Examples\n\nFor more examples, examples/\n\n### examples/go-httpproxy-simple\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\t\"net/http\"\n\n\t\"github.com/go-httpproxy/httpproxy\"\n)\n\nfunc OnError(ctx *httpproxy.Context, where string,\n\terr *httpproxy.Error, opErr error) {\n\t// Log errors.\n\tlog.Printf(\"ERR: %s: %s [%s]\", where, err, opErr)\n}\n\nfunc OnAccept(ctx *httpproxy.Context, w http.ResponseWriter,\n\tr *http.Request) bool {\n\t// Handle local request has path \"/info\"\n\tif r.Method == \"GET\" \u0026\u0026 !r.URL.IsAbs() \u0026\u0026 r.URL.Path == \"/info\" {\n\t\tw.Write([]byte(\"This is go-httpproxy.\"))\n\t\treturn true\n\t}\n\treturn false\n}\n\nfunc OnAuth(ctx *httpproxy.Context, authType string, user string, pass string) bool {\n\t// Auth test user.\n\tif user == \"test\" \u0026\u0026 pass == \"1234\" {\n\t\treturn true\n\t}\n\treturn false\n}\n\nfunc OnConnect(ctx *httpproxy.Context, host string) (\n\tConnectAction httpproxy.ConnectAction, newHost string) {\n\t// Apply \"Man in the Middle\" to all ssl connections. Never change host.\n\treturn httpproxy.ConnectMitm, host\n}\n\nfunc OnRequest(ctx *httpproxy.Context, req *http.Request) (\n\tresp *http.Response) {\n\t// Log proxying requests.\n\tlog.Printf(\"INFO: Proxy: %s %s\", req.Method, req.URL.String())\n\treturn\n}\n\nfunc OnResponse(ctx *httpproxy.Context, req *http.Request,\n\tresp *http.Response) {\n\t// Add header \"Via: go-httpproxy\".\n\tresp.Header.Add(\"Via\", \"go-httpproxy\")\n}\n\nfunc main() {\n\t// Create a new proxy with default certificate pair.\n\tprx, _ := httpproxy.NewProxy()\n\n\t// Set handlers.\n\tprx.OnError = OnError\n\tprx.OnAccept = OnAccept\n\tprx.OnAuth = OnAuth\n\tprx.OnConnect = OnConnect\n\tprx.OnRequest = OnRequest\n\tprx.OnResponse = OnResponse\n\n\t// Listen...\n\thttp.ListenAndServe(\":8080\", prx)\n}\n```\n","funding_links":[],"categories":["Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-httpproxy%2Fhttpproxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgo-httpproxy%2Fhttpproxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-httpproxy%2Fhttpproxy/lists"}