本文整理匯總了Golang中github.com/cloudfoundry/gorouter/test_util.NewHttpConn函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewHttpConn函數的具體用法?Golang NewHttpConn怎麽用?Golang NewHttpConn使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewHttpConn函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: runBackendInstance
func runBackendInstance(ln net.Listener, handler connHandler) {
var tempDelay time.Duration // how long to sleep on accept failure
for {
conn, err := ln.Accept()
if err != nil {
if ne, ok := err.(net.Error); ok && ne.Temporary() {
if tempDelay == 0 {
tempDelay = 5 * time.Millisecond
} else {
tempDelay *= 2
}
if max := 1 * time.Second; tempDelay > max {
tempDelay = max
}
fmt.Printf("http: Accept error: %v; retrying in %v\n", err, tempDelay)
time.Sleep(tempDelay)
continue
}
break
}
go func() {
defer GinkgoRecover()
handler(test_util.NewHttpConn(conn))
}()
}
}
示例2: NewWebSocketApp
func NewWebSocketApp(urls []route.Uri, rPort uint16, mbusClient yagnats.ApceraWrapperNATSClient, delay time.Duration) *TestApp {
app := NewTestApp(urls, rPort, mbusClient, nil)
app.AddHandler("/", func(w http.ResponseWriter, r *http.Request) {
defer ginkgo.GinkgoRecover()
Ω(r.Header.Get("Upgrade")).Should(Equal("websocket"))
Ω(r.Header.Get("Connection")).Should(Equal("upgrade"))
conn, _, err := w.(http.Hijacker).Hijack()
x := test_util.NewHttpConn(conn)
resp := test_util.NewResponse(http.StatusSwitchingProtocols)
resp.Header.Set("Upgrade", "websocket")
resp.Header.Set("Connection", "upgrade")
time.Sleep(delay)
x.WriteResponse(resp)
Ω(err).ShouldNot(HaveOccurred())
x.CheckLine("hello from client")
x.WriteLine("hello from server")
})
return app
}
示例3: registerHandlerWithInstanceId
func registerHandlerWithInstanceId(r *registry.RouteRegistry, u string, h connHandler, instanceId string) net.Listener {
ln, err := net.Listen("tcp", "127.0.0.1:0")
Ω(err).NotTo(HaveOccurred())
go func() {
var tempDelay time.Duration // how long to sleep on accept failure
for {
conn, err := ln.Accept()
if err != nil {
if ne, ok := err.(net.Error); ok && ne.Temporary() {
if tempDelay == 0 {
tempDelay = 5 * time.Millisecond
} else {
tempDelay *= 2
}
if max := 1 * time.Second; tempDelay > max {
tempDelay = max
}
fmt.Printf("http: Accept error: %v; retrying in %v\n", err, tempDelay)
time.Sleep(tempDelay)
continue
}
break
}
go func() {
defer GinkgoRecover()
h(test_util.NewHttpConn(conn))
}()
}
}()
registerAddr(r, u, ln.Addr(), instanceId)
return ln
}
示例4: dialProxy
func dialProxy(proxyServer net.Listener) *test_util.HttpConn {
conn, err := net.Dial("tcp", proxyServer.Addr().String())
Expect(err).NotTo(HaveOccurred())
return test_util.NewHttpConn(conn)
}
示例5:
w.WriteHeader(http.StatusOK)
done <- r.Header.Get(router_http.VcapRequestIdHeader)
})
app.Listen()
go app.RegisterRepeatedly(1 * time.Second)
Eventually(func() bool {
return appRegistered(registry, app)
}).Should(BeTrue())
conn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", config.Ip, config.Port))
Expect(err).NotTo(HaveOccurred())
defer conn.Close()
httpConn := test_util.NewHttpConn(conn)
req := test_util.NewRequest("GET", "foo.vcap.me", "/", nil)
req.Header.Add(router_http.VcapRequestIdHeader, "A-BOGUS-REQUEST-ID")
httpConn.WriteRequest(req)
var answer string
Eventually(done).Should(Receive(&answer))
Expect(answer).ToNot(Equal("A-BOGUS-REQUEST-ID"))
Expect(answer).To(MatchRegexp(uuid_regex))
Expect(logger).To(gbytes.Say("vcap-request-id-header-set"))
resp, _ := httpConn.ReadResponse()
Expect(resp.StatusCode).To(Equal(http.StatusOK))
})