本文整理汇总了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))
}()
}
}
开发者ID:sunatthegilddotcom,项目名称:gorouter,代码行数:26,代码来源:proxy_test.go
示例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
}
开发者ID:johannespetzold,项目名称:gorouter,代码行数:26,代码来源:websocket_app.go
示例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
}
开发者ID:tomzhang,项目名称:golang-devops-stuff,代码行数:35,代码来源:proxy_test.go
示例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)
}
开发者ID:sunatthegilddotcom,项目名称:gorouter,代码行数:6,代码来源:proxy_test.go
示例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))
})
开发者ID:rakutentech,项目名称:gorouter,代码行数:31,代码来源:router_test.go
注:本文中的github.com/cloudfoundry/gorouter/test_util.NewHttpConn函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论