Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/getlantern/http-proxy-archived

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/getlantern/http-proxy-archived

  • v0.0.2
  • Source
  • Go
  • Socket score

Version published
Created
Source

HTTP Proxy in Go

Build Status

Run

First get dependencies:

go get -t

Then run with:

go run http_proxy.go

Build your own Proxy

This proxy is built around the classical Middleware pattern. You can see examples in the forward and httpconnect packges. They can be chained together forming a series of filters.

See this code snippet:

// Middleware: Forward HTTP Messages
forwarder, err := forward.New(nil, forward.IdleTimeoutSetter(time.Duration(*idleClose)*time.Second))
if err != nil {
	log.Error(err)
}

// Middleware: Handle HTTP CONNECT
httpConnect, err := httpconnect.New(forwarder, httpconnect.IdleTimeoutSetter(time.Duration(*idleClose)*time.Second))
if err != nil {
	log.Error(err)
}

...

Additionally, this proxy uses the concept of connection wrappers, which work as a series of wrappers over the listeners generating the connections, and the connections themselves.

The following is an extract of the default listeners you can find in this proxy. You need to provide functions that take the previous listener and produce a new one, wrapping it in the process. Note that the generated connections must implement StateAwareConn. See more examples in listeners.

srv.AddListenerWrappers(
	// Limit max number of simultaneous connections
	func(ls net.Listener) net.Listener {
		return listeners.NewLimitedListener(ls, *maxConns)
	},

    // Close connections after 30 seconds of no activity
	func(ls net.Listener) net.Listener {
		return listeners.NewIdleConnListener(ls, time.Duration(*idleClose)*time.Second)
	},
)

Test

Run tests

go test

Use this for verbose output:

TRACE=1 go test

Manual testing

*Keep in mind that cURL doesn't support tunneling through an HTTPS proxy, so if you use the -https option you have to use other tools for testing.

Run the server as follows:

go run http_proxy.go

Test direct proxying with cURL:

curl -kvx localhost:8080 http://www.google.com/humans.txt
curl -kvx localhost:8080 https://www.google.com/humans.txt

Test HTTP connect with cURL:

curl -kpvx localhost:8080 http://www.google.com/humans.txt
curl -kpvx localhost:8080 https://www.google.com/humans.txt

FAQs

Package last updated on 12 Nov 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc