• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang test_util.NewResponse函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/cloudfoundry/gorouter/test_util.NewResponse函数的典型用法代码示例。如果您正苦于以下问题:Golang NewResponse函数的具体用法?Golang NewResponse怎么用?Golang NewResponse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewResponse函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: 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


示例2: shouldEcho

func shouldEcho(input string, expected string) {
	ln := registerHandler(r, "encoding", func(x *test_util.HttpConn) {
		x.CheckLine("GET " + expected + " HTTP/1.1")
		resp := test_util.NewResponse(http.StatusOK)
		x.WriteResponse(resp)
		x.Close()
	})
	defer ln.Close()

	x := dialProxy(proxyServer)

	req := test_util.NewRequest("GET", "encoding", input, nil)
	x.WriteRequest(req)
	resp, _ := x.ReadResponse()

	Expect(resp.StatusCode).To(Equal(http.StatusOK))
}
开发者ID:sunatthegilddotcom,项目名称:gorouter,代码行数:17,代码来源:proxy_suite_test.go


示例3:

	"github.com/cloudfoundry/gorouter/proxy"
	"github.com/cloudfoundry/gorouter/test_util"

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

var _ = Describe("Session Affinity", func() {
	var done chan bool
	var jSessionIdCookie *http.Cookie

	responseNoCookies := func(x *test_util.HttpConn) {
		_, err := http.ReadRequest(x.Reader)
		Expect(err).ToNot(HaveOccurred())

		resp := test_util.NewResponse(http.StatusOK)
		x.WriteResponse(resp)
		x.Close()
		done <- true
	}

	responseWithJSessionID := func(x *test_util.HttpConn) {
		_, err := http.ReadRequest(x.Reader)
		Expect(err).ToNot(HaveOccurred())

		resp := test_util.NewResponse(http.StatusOK)
		resp.Header.Add("Set-Cookie", jSessionIdCookie.String())
		x.WriteResponse(resp)
		x.Close()
		done <- true
	}
开发者ID:idouba,项目名称:gorouter,代码行数:31,代码来源:session_affinity_test.go


示例4: MarshalJSON

func (_ nullVarz) MarshalJSON() ([]byte, error)                                                     { return json.Marshal(nil) }
func (_ nullVarz) ActiveApps() *stats.ActiveApps                                                    { return stats.NewActiveApps() }
func (_ nullVarz) CaptureBadRequest(*http.Request)                                                  {}
func (_ nullVarz) CaptureBadGateway(*http.Request)                                                  {}
func (_ nullVarz) CaptureRoutingRequest(b *route.Endpoint, req *http.Request)                       {}
func (_ nullVarz) CaptureRoutingResponse(*route.Endpoint, *http.Response, time.Time, time.Duration) {}
func (_ nullVarz) CaptureRegistryMessage(msg metrics.ComponentTagged)                               {}

var _ = Describe("Proxy", func() {

	It("responds to http/1.0 with path", func() {
		ln := registerHandler(r, "test/my_path", func(conn *test_util.HttpConn) {
			conn.CheckLine("GET /my_path HTTP/1.1")

			conn.WriteResponse(test_util.NewResponse(http.StatusOK))
		})
		defer ln.Close()

		conn := dialProxy(proxyServer)

		conn.WriteLines([]string{
			"GET /my_path HTTP/1.0",
			"Host: test",
		})

		conn.CheckLine("HTTP/1.0 200 OK")
	})

	It("responds transparently to a trailing slash versus no trailing slash", func() {
		lnWithoutSlash := registerHandler(r, "test/my%20path/your_path", func(conn *test_util.HttpConn) {
开发者ID:sunatthegilddotcom,项目名称:gorouter,代码行数:30,代码来源:proxy_test.go


示例5:

		req := x.NewRequest("GET", "/", nil)
		req.Host = "enfant-terrible"
		x.WriteRequest(req)

		resp, body := x.ReadResponse()
		Ω(resp.StatusCode).To(Equal(http.StatusBadGateway))
		Ω(resp.Header.Get("X-Cf-RouterError")).To(Equal("endpoint_failure"))
		Ω(body).To(Equal("502 Bad Gateway: Registered endpoint failed to handle the request.\n"))
	})

	It("trace headers added on correct TraceKey", func() {
		ln := registerHandler(r, "trace-test", func(x *test_util.HttpConn) {
			_, err := http.ReadRequest(x.Reader)
			Ω(err).NotTo(HaveOccurred())

			resp := test_util.NewResponse(http.StatusOK)
			x.WriteResponse(resp)
			x.Close()
		})
		defer ln.Close()

		x := dialProxy(proxyServer)

		req := x.NewRequest("GET", "/", nil)
		req.Host = "trace-test"
		req.Header.Set(router_http.VcapTraceHeader, "my_trace_key")
		x.WriteRequest(req)

		resp, _ := x.ReadResponse()
		Ω(resp.StatusCode).To(Equal(http.StatusOK))
		Ω(resp.Header.Get(router_http.VcapBackendHeader)).To(Equal(ln.Addr().String()))
开发者ID:tomzhang,项目名称:golang-devops-stuff,代码行数:31,代码来源:proxy_test.go



注:本文中的github.com/cloudfoundry/gorouter/test_util.NewResponse函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang test_util.NextAvailPort函数代码示例发布时间:2022-05-23
下一篇:
Golang test_util.NewRequest函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap