{"id":37207162,"url":"https://github.com/zoonru/httpproxy","last_synced_at":"2026-01-14T23:49:55.817Z","repository":{"id":44765875,"uuid":"252429260","full_name":"zoonru/httpproxy","owner":"zoonru","description":"Go HTTP proxy server library","archived":false,"fork":true,"pushed_at":"2022-01-26T07:32:24.000Z","size":75,"stargazers_count":0,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-04T03:28:08.904Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"go-httpproxy/httpproxy","license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zoonru.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":"2020-04-02T10:53:43.000Z","updated_at":"2022-01-26T07:32:27.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/zoonru/httpproxy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zoonru/httpproxy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoonru%2Fhttpproxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoonru%2Fhttpproxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoonru%2Fhttpproxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoonru%2Fhttpproxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zoonru","download_url":"https://codeload.github.com/zoonru/httpproxy/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoonru%2Fhttpproxy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28439551,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T22:37:52.437Z","status":"ssl_error","status_checked_at":"2026-01-14T22:37:31.496Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2026-01-14T23:49:55.183Z","updated_at":"2026-01-14T23:49:55.795Z","avatar_url":"https://github.com/zoonru.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"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/zoonru/httpproxy\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzoonru%2Fhttpproxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzoonru%2Fhttpproxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzoonru%2Fhttpproxy/lists"}