Exemple #1
0
func main() {
	var proxy *goproxy.ProxyHttpServer
	app.Main(func(a app.App) {
		var sz size.Event
		for e := range a.Events() {
			switch e := app.Filter(e).(type) {
			case lifecycle.Event:
				if e.Crosses(lifecycle.StageAlive) == lifecycle.CrossOn && proxy == nil {
					proxy = goproxy.NewProxyHttpServer()
					//proxy.Verbose = true
					re := regexp.MustCompile(`.*`)
					proxy.OnResponse(goproxy.UrlMatches(re)).DoFunc(
						func(res *http.Response, ctx *goproxy.ProxyCtx) *http.Response {
							if label != nil {
								label.Text = fmt.Sprintf("%s\n%s\n", ctx.Req.URL, label.Text)
								log.Println(ctx.Req.URL)
							}
							return res
						})
					go func() {
						log.Fatal(http.ListenAndServe(":8888", proxy))
					}()
				}
			case paint.Event:
				onPaint(sz)
				a.EndPaint(e)
			case size.Event:
				sz = e
			}
		}
	})
}
Exemple #2
0
func listenTransparentTLS(proxy *goproxy.ProxyHttpServer, addr string,
	timeout time.Duration) error {

	// listen to the TLS ClientHello but make it a CONNECT request instead
	ln, err := net.Listen("tcp", addr)
	if err != nil {
		return err
	}
	for {
		c, err := ln.Accept()
		if err != nil {
			log.Printf("error accepting new connection - %v", err)
			continue
		}
		go func(c net.Conn) {
			c.SetDeadline(time.Now().Add(timeout))
			tlsConn, err := vhost.TLS(c)
			if err != nil {
				log.Printf("error accepting new connection - %v", err)
			}
			if tlsConn.Host() == "" {
				log.Printf("cannot support non-SNI enabled clients")
				return
			}
			connectReq := &http.Request{
				Method: "CONNECT",
				URL: &url.URL{
					Opaque: tlsConn.Host(),
					Host:   net.JoinHostPort(tlsConn.Host(), "443"),
				},
				Host:   tlsConn.Host(),
				Header: make(http.Header),
			}
			resp := dumbResponseWriter{tlsConn}
			proxy.ServeHTTP(resp, connectReq)
		}(c)
	}
}
Exemple #3
0
// ProxyBasic will force HTTP authentication before any request to the proxy is processed
func ProxyBasic(proxy *goproxy.ProxyHttpServer, realm string, f func(user, passwd string) bool) {
	proxy.OnRequest().Do(Basic(realm, f))
	proxy.OnRequest().HandleConnect(BasicConnect(realm, f))
}
Exemple #4
0
// copied/converted from https.go
func connectDial(proxy *goproxy.ProxyHttpServer, network, addr string) (c net.Conn, err error) {
	if proxy.ConnectDial == nil {
		return dial(proxy, network, addr)
	}
	return proxy.ConnectDial(network, addr)
}
	"github.com/cloudfoundry/noaa/events"
	"github.com/elazarl/goproxy"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Noaa behind a Proxy", func() {
	var (
		connection        *noaa.Consumer
		endpoint          string
		testServer        *httptest.Server
		tlsSettings       *tls.Config
		consumerProxyFunc func(*http.Request) (*url.URL, error)

		appGuid         string
		authToken       string
		incomingChan    chan *events.Envelope
		messagesToSend  chan []byte
		testProxyServer *httptest.Server
		goProxyHandler  *goproxy.ProxyHttpServer

		err error
	)

	BeforeEach(func() {
		messagesToSend = make(chan []byte, 256)

		testServer = httptest.NewServer(handlers.NewWebsocketHandler(messagesToSend, 100*time.Millisecond, loggertesthelper.Logger()))
		endpoint = "ws://" + testServer.Listener.Addr().String()
		goProxyHandler = goproxy.NewProxyHttpServer()
		goProxyHandler.Logger = log.New(bytes.NewBufferString(""), "", 0)
	"github.com/cloudfoundry/noaa/consumer"
	"github.com/cloudfoundry/sonde-go/events"
	"github.com/elazarl/goproxy"
	"github.com/elazarl/goproxy/ext/auth"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Consumer connecting through a Proxy", func() {
	var (
		connection *consumer.Consumer

		messagesToSend chan []byte
		testServer     *httptest.Server
		endpoint       string
		proxy          func(*http.Request) (*url.URL, error)

		testProxyServer *httptest.Server
		goProxyHandler  *goproxy.ProxyHttpServer
	)

	BeforeEach(func() {
		messagesToSend = make(chan []byte, 256)
		testServer = httptest.NewServer(handlers.NewWebsocketHandler(messagesToSend, 100*time.Millisecond, loggertesthelper.Logger()))
		endpoint = "ws://" + testServer.Listener.Addr().String()

		goProxyHandler = goproxy.NewProxyHttpServer()
		goProxyHandler.Logger = log.New(bytes.NewBufferString(""), "", 0)
		testProxyServer = httptest.NewServer(goProxyHandler)
		proxy = func(*http.Request) (*url.URL, error) {