Top Related Projects
An interactive TLS-capable intercepting HTTP proxy for penetration testers and software developers.
A platform for building proxies to bypass network restrictions.
Lantern官方版本下载 蓝灯 翻墙 代理 科学上网 外网 加速器 梯子 路由 - Быстрый, надежный и безопасный доступ к открытому интернету - lantern proxy vpn censorship-circumvention censorship gfw accelerator پراکسی لنترن، ضدسانسور، امن، قابل اعتماد و پرسرعت
go port of shadowsocks (Deprecated)
GO Simple Tunnel - a simple tunnel written in golang
Quick Overview
GoProxy is an HTTP/HTTPS proxy library for Go. It provides a customizable proxy server that can be used to intercept, modify, and forward HTTP and HTTPS requests and responses. This library is particularly useful for debugging, testing, and implementing custom proxy behavior in Go applications.
Pros
- Easy to use and integrate into existing Go projects
- Supports both HTTP and HTTPS traffic interception
- Highly customizable with hooks for modifying requests and responses
- Actively maintained with regular updates and bug fixes
Cons
- Limited documentation and examples for advanced use cases
- May require additional configuration for complex proxy scenarios
- Performance may be impacted when handling large volumes of traffic
- Lacks built-in support for some advanced proxy features (e.g., caching, load balancing)
Code Examples
- Creating a basic proxy server:
package main
import (
"github.com/elazarl/goproxy"
"log"
"net/http"
)
func main() {
proxy := goproxy.NewProxyHttpServer()
log.Fatal(http.ListenAndServe(":8080", proxy))
}
- Modifying requests:
proxy.OnRequest().DoFunc(func(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
r.Header.Set("X-GoProxy", "true")
return r, nil
})
- Blocking specific domains:
proxy.OnRequest(goproxy.DstHostIs("example.com")).DoFunc(func(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
return r, goproxy.NewResponse(r, goproxy.ContentTypeText, http.StatusForbidden, "Blocked")
})
- Logging requests:
proxy.OnRequest().DoFunc(func(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
log.Printf("Request: %s %s", r.Method, r.URL)
return r, nil
})
Getting Started
To use GoProxy in your Go project, follow these steps:
-
Install the library:
go get github.com/elazarl/goproxy
-
Import the library in your Go code:
import "github.com/elazarl/goproxy"
-
Create a new proxy server and start listening:
proxy := goproxy.NewProxyHttpServer() log.Fatal(http.ListenAndServe(":8080", proxy))
-
Customize the proxy behavior by adding request and response handlers as needed.
Competitor Comparisons
An interactive TLS-capable intercepting HTTP proxy for penetration testers and software developers.
Pros of mitmproxy
- More feature-rich with a command-line interface, web interface, and Python scripting support
- Better documentation and active community support
- Supports HTTP/2 and WebSockets
Cons of mitmproxy
- Written in Python, which may be slower than Go for certain operations
- Larger codebase and potentially more complex to contribute to
- Steeper learning curve for users not familiar with Python
Code Comparison
mitmproxy (Python):
def request(flow: http.HTTPFlow) -> None:
if flow.request.pretty_host == "example.com":
flow.request.headers["Custom-Header"] = "Value"
goproxy (Go):
goproxy.OnRequest().DoFunc(func(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
if r.Host == "example.com" {
r.Header.Set("Custom-Header", "Value")
}
return r, nil
})
Both examples show how to modify headers for requests to a specific host, demonstrating the syntax differences between Python and Go. mitmproxy's approach is more concise, while goproxy's is more explicit in its function structure.
A platform for building proxies to bypass network restrictions.
Pros of v2ray-core
- More comprehensive networking protocol support, including VMess, VLESS, and Trojan
- Advanced routing capabilities with flexible rule-based traffic routing
- Better suited for complex network environments and bypassing censorship
Cons of v2ray-core
- Steeper learning curve due to its complexity and extensive configuration options
- Higher resource consumption compared to the lightweight goproxy
Code Comparison
v2ray-core (config example):
{
"inbounds": [{
"port": 1080,
"protocol": "socks",
"settings": {
"auth": "noauth"
}
}],
"outbounds": [{
"protocol": "freedom"
}]
}
goproxy (usage example):
proxy := goproxy.NewProxyHttpServer()
proxy.Verbose = true
log.Fatal(http.ListenAndServe(":8080", proxy))
Summary
v2ray-core offers more advanced features and protocol support, making it suitable for complex networking scenarios and circumventing censorship. However, it comes with a steeper learning curve and higher resource usage. goproxy, on the other hand, is simpler to use and more lightweight, but lacks some of the advanced features found in v2ray-core. The choice between the two depends on the specific requirements of the project and the level of complexity needed.
Lantern官方版本下载 蓝灯 翻墙 代理 科学上网 外网 加速器 梯子 路由 - Быстрый, надежный и безопасный доступ к открытому интернету - lantern proxy vpn censorship-circumvention censorship gfw accelerator پراکسی لنترن، ضدسانسور، امن، قابل اعتماد و پرسرعت
Pros of Lantern
- Full-featured censorship circumvention tool with a user-friendly GUI
- Supports multiple protocols and advanced features like traffic obfuscation
- Active development with frequent updates and a large user base
Cons of Lantern
- More complex setup and configuration compared to Goproxy
- Heavier resource usage due to additional features and GUI
- May be overkill for simple proxy needs
Code Comparison
Lantern (main proxy handling):
func (proxy *Proxy) Handle(ctx context.Context, conn net.Conn) error {
// Complex connection handling with multiple protocols
// ...
}
Goproxy (main proxy handling):
func (proxy *ProxyHttpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Simpler HTTP-focused proxy handling
// ...
}
Lantern offers a more comprehensive solution for censorship circumvention with advanced features, while Goproxy provides a simpler, lightweight HTTP/HTTPS proxy implementation. Lantern is better suited for end-users needing robust censorship bypass, while Goproxy is more appropriate for developers integrating proxy functionality into their applications or for simpler proxy requirements.
go port of shadowsocks (Deprecated)
Pros of shadowsocks-go
- Designed specifically for circumventing internet censorship
- Implements the SOCKS5 proxy protocol, which is more versatile for various applications
- Offers encryption and obfuscation features for enhanced privacy and security
Cons of shadowsocks-go
- Less actively maintained compared to goproxy
- More complex setup and configuration process
- Limited to SOCKS5 proxy functionality, while goproxy supports HTTP/HTTPS as well
Code Comparison
shadowsocks-go:
cipher := ss.NewCipher(config.Method, config.Password)
listenAddr := net.JoinHostPort(config.Server, config.ServerPort)
ln, err := net.Listen("tcp", listenAddr)
goproxy:
proxy := goproxy.NewProxyHttpServer()
proxy.Verbose = true
log.Fatal(http.ListenAndServe(":8080", proxy))
The code snippets highlight the different focus of each project. shadowsocks-go emphasizes encryption and custom network protocols, while goproxy provides a simpler setup for HTTP proxy functionality.
GO Simple Tunnel - a simple tunnel written in golang
Pros of gost
- More comprehensive proxy solution with support for multiple protocols (HTTP, SOCKS4, SOCKS5, Shadowsocks, etc.)
- Built-in encryption and obfuscation features for enhanced security
- Supports chaining of multiple proxies for increased anonymity
Cons of gost
- More complex configuration due to its extensive feature set
- Potentially higher resource usage compared to goproxy's lightweight design
- Less focused on HTTP proxy functionality, which may be overkill for simple use cases
Code Comparison
goproxy:
proxy := goproxy.NewProxyHttpServer()
proxy.Verbose = true
log.Fatal(http.ListenAndServe(":8080", proxy))
gost:
chain := gost.NewChain(
gost.Node{Protocol: "http", Addr: ":8080"},
gost.Node{Protocol: "socks5", Addr: ":1080"},
)
log.Fatal(chain.Run())
The code snippets demonstrate that goproxy is more straightforward for setting up a simple HTTP proxy, while gost offers more flexibility in configuring multiple proxy types and chaining them together.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Introduction
Package goproxy provides a customizable HTTP proxy library for Go (golang),
It supports regular HTTP proxy, HTTPS through CONNECT, and "hijacking" HTTPS connection using "Man in the Middle" style attack.
The intent of the proxy is to be usable with reasonable amount of traffic, yet customizable and programmable.
The proxy itself is simply a net/http
handler.
In order to use goproxy, one should set their browser to use goproxy as an HTTP proxy. Here is how you do that in Chrome and in Firefox.
For example, the URL you should use as proxy when running ./bin/basic
is
localhost:8080
, as this is the default binding for the basic proxy.
Mailing List
New features will be discussed on the mailing list before their development.
Latest Stable Release
Get the latest goproxy from gopkg.in/elazarl/goproxy.v1
.
Why not Fiddler2?
Fiddler is an excellent software with similar intent. However, Fiddler is not as customizable as goproxy intends to be. The main difference is, Fiddler is not intended to be used as a real proxy.
A possible use case that suits goproxy but not Fiddler, is gathering statistics on page load times for a certain website over a week. With goproxy you could ask all your users to set their proxy to a dedicated machine running a goproxy server. Fiddler is a GUI app not designed to be run like a server for multiple users.
A taste of goproxy
To get a taste of goproxy
, a basic HTTP/HTTPS transparent proxy
package main
import (
"github.com/elazarl/goproxy"
"log"
"net/http"
)
func main() {
proxy := goproxy.NewProxyHttpServer()
proxy.Verbose = true
log.Fatal(http.ListenAndServe(":8080", proxy))
}
This line will add X-GoProxy: yxorPoG-X
header to all requests sent through the proxy
proxy.OnRequest().DoFunc(
func(r *http.Request,ctx *goproxy.ProxyCtx)(*http.Request,*http.Response) {
r.Header.Set("X-GoProxy","yxorPoG-X")
return r,nil
})
DoFunc
will process all incoming requests to the proxy. It will add a header to the request
and return it. The proxy will send the modified request.
Note that we returned nil value as the response. Had we returned a response, goproxy would have discarded the request and sent the new response to the client.
In order to refuse connections to reddit at work time
proxy.OnRequest(goproxy.DstHostIs("www.reddit.com")).DoFunc(
func(r *http.Request,ctx *goproxy.ProxyCtx)(*http.Request,*http.Response) {
if h,_,_ := time.Now().Clock(); h >= 8 && h <= 17 {
return r,goproxy.NewResponse(r,
goproxy.ContentTypeText,http.StatusForbidden,
"Don't waste your time!")
}
return r,nil
})
DstHostIs
returns a ReqCondition
, that is a function receiving a Request
and returning a boolean.
We will only process requests that match the condition. DstHostIs("www.reddit.com")
will return
a ReqCondition
accepting only requests directed to "www.reddit.com".
DoFunc
will receive a function that will preprocess the request. We can change the request, or
return a response. If the time is between 8:00am and 17:00pm, we will reject the request, and
return a pre-canned text response saying "do not waste your time".
See additional examples in the examples directory.
Type of handlers for manipulating connect/req/resp behavior
There are 3 kinds of useful handlers to manipulate the behavior, as follows:
// handler called after receiving HTTP CONNECT from the client, and before proxy establish connection
// with destination host
httpsHandlers []HttpsHandler
// handler called before proxy send HTTP request to destination host
reqHandlers []ReqHandler
// handler called after proxy receives HTTP Response from destination host, and before proxy forward
// the Response to the client.
respHandlers []RespHandler
Depending on what you want to manipulate, the ways to add handlers to each handler list are:
// Add handlers to httpsHandlers
proxy.OnRequest(Some ReqConditions).HandleConnect(YourHandlerFunc())
// Add handlers to reqHandlers
proxy.OnRequest(Some ReqConditions).Do(YourReqHandlerFunc())
// Add handlers to respHandlers
proxy.OnResponse(Some RespConditions).Do(YourRespHandlerFunc())
For example:
// This rejects the HTTPS request to *.reddit.com during HTTP CONNECT phase
proxy.OnRequest(goproxy.ReqHostMatches(regexp.MustCompile("reddit.*:443$"))).HandleConnect(goproxy.AlwaysReject)
// This will NOT reject the HTTPS request with URL ending with gif, due to the fact that proxy
// only got the URL.Hostname and URL.Port during the HTTP CONNECT phase if the scheme is HTTPS, which is
// quiet common these days.
proxy.OnRequest(goproxy.UrlMatches(regexp.MustCompile(`.*gif$`))).HandleConnect(goproxy.AlwaysReject)
// The correct way to manipulate the HTTP request using URL.Path as condition is:
proxy.OnRequest(goproxy.UrlMatches(regexp.MustCompile(`.*gif$`))).Do(YourReqHandlerFunc())
What's New
- Ability to
Hijack
CONNECT requests. See the eavesdropper example - Transparent proxy support for http/https including MITM certificate generation for TLS. See the transparent example.
License
I put the software temporarily under the Go-compatible BSD license. If this prevents someone from using the software, do let me know and I'll consider changing it.
At any rate, user feedback is very important for me, so I'll be delighted to know if you're using this package.
Beta Software
I've received positive feedback from a few people who use goproxy in production settings. I believe it is good enough for usage.
I'll try to keep reasonable backwards compatibility. In case of a major API change, I'll change the import path.
Top Related Projects
An interactive TLS-capable intercepting HTTP proxy for penetration testers and software developers.
A platform for building proxies to bypass network restrictions.
Lantern官方版本下载 蓝灯 翻墙 代理 科学上网 外网 加速器 梯子 路由 - Быстрый, надежный и безопасный доступ к открытому интернету - lantern proxy vpn censorship-circumvention censorship gfw accelerator پراکسی لنترن، ضدسانسور، امن، قابل اعتماد و پرسرعت
go port of shadowsocks (Deprecated)
GO Simple Tunnel - a simple tunnel written in golang
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot