本文整理匯總了Golang中github.com/elazarl/goproxy.ProxyHttpServer類的典型用法代碼示例。如果您正苦於以下問題:Golang ProxyHttpServer類的具體用法?Golang ProxyHttpServer怎麽用?Golang ProxyHttpServer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ProxyHttpServer類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
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
}
}
})
}
示例2: listenTransparentTLS
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)
}
}
示例3: ProxyBasic
// 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))
}
示例4: connectDial
// 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)
}
示例5:
"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)
示例6:
"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) {