本文整理汇总了Golang中github.com/vulcand/oxy/testutils.Host函数的典型用法代码示例。如果您正苦于以下问题:Golang Host函数的具体用法?Golang Host怎么用?Golang Host使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Host函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestListenerScopeUpdate
func (s *ServerSuite) TestListenerScopeUpdate(c *C) {
e := testutils.NewResponder("Hi, I'm endpoint")
defer e.Close()
c.Assert(s.mux.Start(), IsNil)
b := MakeBatch(Batch{Addr: "localhost:41000", Route: `Path("/")`, URL: e.URL})
c.Assert(s.mux.UpsertServer(b.BK, b.S), IsNil)
c.Assert(s.mux.UpsertFrontend(b.F), IsNil)
c.Assert(s.mux.UpsertListener(b.L), IsNil)
re, body, err := testutils.Get(b.FrontendURL("/"), testutils.Host("otherhost"))
c.Assert(err, IsNil)
c.Assert(re.StatusCode, Equals, http.StatusOK)
c.Assert(string(body), Equals, "Hi, I'm endpoint")
b.L.Scope = `Host("localhost")`
c.Assert(s.mux.UpsertListener(b.L), IsNil)
re, body, err = testutils.Get(b.FrontendURL("/"), testutils.Host("localhost"))
c.Assert(err, IsNil)
c.Assert(re.StatusCode, Equals, http.StatusOK)
c.Assert(string(body), Equals, "Hi, I'm endpoint")
re, _, err = testutils.Get(b.FrontendURL("/"), testutils.Host("otherhost"))
c.Assert(err, IsNil)
c.Assert(re.StatusCode, Equals, http.StatusNotFound)
}
开发者ID:vnadgir-ef,项目名称:vulcand,代码行数:29,代码来源:mux_test.go
示例2: TestSameHeaderMulti
func (s *RewriteSuite) TestSameHeaderMulti(c *C) {
var outURL string
handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
outURL = rawURL(req)
w.Write([]byte("hello"))
})
rh, err := newRewriteHandler(handler,
&Rewrite{
"^http://localhost/(foo)/(bar)$",
`http://localhost/$1/{{.Request.Header.Get "X-Header"}}/$2/{{.Request.Header.Get "X-Header"}}`, false, false})
c.Assert(rh, NotNil)
c.Assert(err, IsNil)
srv := httptest.NewServer(rh)
defer srv.Close()
re, _, err := testutils.Get(srv.URL+"/foo/bar",
testutils.Host("localhost"), testutils.Header("X-Header", "baz"))
c.Assert(err, IsNil)
c.Assert(re.StatusCode, Equals, http.StatusOK)
c.Assert(outURL, Equals, "http://localhost/foo/baz/bar/baz")
}
开发者ID:vnadgir-ef,项目名称:vulcand,代码行数:25,代码来源:rewrite_test.go
示例3: TestSNI
func (s *ServerSuite) TestSNI(c *C) {
e := testutils.NewResponder("Hi, I'm endpoint 1")
defer e.Close()
e2 := testutils.NewResponder("Hi, I'm endpoint 2")
defer e2.Close()
c.Assert(s.mux.Start(), IsNil)
b := MakeBatch(Batch{
Host: "localhost",
Addr: "localhost:41000",
Route: `Host("localhost") && Path("/")`,
URL: e.URL,
Protocol: engine.HTTPS,
KeyPair: &engine.KeyPair{Key: localhostKey, Cert: localhostCert},
})
b2 := MakeBatch(Batch{
Host: "otherhost",
Addr: "localhost:41000",
Route: `Host("otherhost") && Path("/")`,
URL: e2.URL,
Protocol: engine.HTTPS,
KeyPair: &engine.KeyPair{Key: localhostKey2, Cert: localhostCert2},
})
b2.H.Settings.Default = true
c.Assert(s.mux.UpsertHost(b.H), IsNil)
c.Assert(s.mux.UpsertHost(b2.H), IsNil)
c.Assert(s.mux.UpsertServer(b.BK, b.S), IsNil)
c.Assert(s.mux.UpsertServer(b2.BK, b2.S), IsNil)
c.Assert(s.mux.UpsertFrontend(b.F), IsNil)
c.Assert(s.mux.UpsertFrontend(b2.F), IsNil)
c.Assert(s.mux.UpsertListener(b.L), IsNil)
c.Assert(GETResponse(c, b.FrontendURL("/"), testutils.Host("localhost")), Equals, "Hi, I'm endpoint 1")
c.Assert(GETResponse(c, b.FrontendURL("/"), testutils.Host("otherhost")), Equals, "Hi, I'm endpoint 2")
}
开发者ID:vnadgir-ef,项目名称:vulcand,代码行数:42,代码来源:mux_test.go
示例4: TestTwoHosts
// Test case when you have two hosts on the same socket
func (s *ServerSuite) TestTwoHosts(c *C) {
e := testutils.NewResponder("Hi, I'm endpoint 1")
defer e.Close()
e2 := testutils.NewResponder("Hi, I'm endpoint 2")
defer e2.Close()
c.Assert(s.mux.Start(), IsNil)
b := MakeBatch(Batch{Addr: "localhost:41000", Route: `Host("localhost") && Path("/")`, URL: e.URL})
b2 := MakeBatch(Batch{Addr: "localhost:41000", Route: `Host("otherhost") && Path("/")`, URL: e2.URL})
c.Assert(s.mux.UpsertServer(b.BK, b.S), IsNil)
c.Assert(s.mux.UpsertServer(b2.BK, b2.S), IsNil)
c.Assert(s.mux.UpsertFrontend(b.F), IsNil)
c.Assert(s.mux.UpsertFrontend(b2.F), IsNil)
c.Assert(s.mux.UpsertListener(b.L), IsNil)
c.Assert(GETResponse(c, b.FrontendURL("/"), testutils.Host("localhost")), Equals, "Hi, I'm endpoint 1")
c.Assert(GETResponse(c, b.FrontendURL("/"), testutils.Host("otherhost")), Equals, "Hi, I'm endpoint 2")
}
开发者ID:vnadgir-ef,项目名称:vulcand,代码行数:24,代码来源:mux_test.go
示例5: TestRedirect
func (s *RewriteSuite) TestRedirect(c *C) {
handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte("hello"))
})
rh, err := newRewriteHandler(handler, &Rewrite{"^http://localhost/(foo)/(bar)", "https://localhost/$2", false, true})
c.Assert(rh, NotNil)
c.Assert(err, IsNil)
srv := httptest.NewServer(rh)
defer srv.Close()
re, _, err := testutils.Get(srv.URL+"/foo/bar", testutils.Host("localhost"))
c.Assert(re.StatusCode, Equals, http.StatusFound)
c.Assert(re.Header.Get("Location"), Equals, "https://localhost/bar")
}
开发者ID:vnadgir-ef,项目名称:vulcand,代码行数:16,代码来源:rewrite_test.go
示例6: TestRewriteNoMatch
func (s *RewriteSuite) TestRewriteNoMatch(c *C) {
var outURL string
handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
outURL = rawURL(req)
w.Write([]byte("hello"))
})
rh, err := newRewriteHandler(handler, &Rewrite{"^http://localhost/foo/(.*)", "http://localhost$1", false, false})
c.Assert(rh, NotNil)
c.Assert(err, IsNil)
srv := httptest.NewServer(rh)
defer srv.Close()
re, _, err := testutils.Get(srv.URL+"/fooo/bar", testutils.Host("localhost"))
c.Assert(err, IsNil)
c.Assert(re.StatusCode, Equals, http.StatusOK)
c.Assert(outURL, Equals, "http://localhost/fooo/bar")
}
开发者ID:vnadgir-ef,项目名称:vulcand,代码行数:19,代码来源:rewrite_test.go
示例7: TestDontRewriteResponseBody
func (s *RewriteSuite) TestDontRewriteResponseBody(c *C) {
handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte(`{"foo": "{{.Request.Header.Get "X-Header"}}"}`))
})
rh, err := newRewriteHandler(handler, &Rewrite{"", "", false, false})
c.Assert(rh, NotNil)
c.Assert(err, IsNil)
srv := httptest.NewServer(rh)
defer srv.Close()
re, body, err := testutils.Get(srv.URL,
testutils.Host("localhost"),
testutils.Header("X-Header", "bar"))
c.Assert(re.StatusCode, Equals, http.StatusOK)
c.Assert(string(body), Equals, `{"foo": "{{.Request.Header.Get "X-Header"}}"}`)
}
开发者ID:vnadgir-ef,项目名称:vulcand,代码行数:19,代码来源:rewrite_test.go
示例8: TestRewriteInQuery
func (s *RewriteSuite) TestRewriteInQuery(c *C) {
var outURL string
handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
outURL = rawURL(req)
w.Write([]byte("hello"))
})
rh, err := newRewriteHandler(handler, &Rewrite{"^http://localhost/foo\\?(.*)=(.*)", `http://localhost/foo?$1={{.Request.Header.Get "X-Header"}}`, false, false})
c.Assert(rh, NotNil)
c.Assert(err, IsNil)
srv := httptest.NewServer(rh)
defer srv.Close()
re, _, err := testutils.Get(srv.URL+"/foo?a=b", testutils.Host("localhost"), testutils.Header("X-Header", "xxx"))
c.Assert(err, IsNil)
c.Assert(re.StatusCode, Equals, http.StatusOK)
c.Assert(outURL, Equals, "http://localhost/foo?a=xxx")
}
开发者ID:vnadgir-ef,项目名称:vulcand,代码行数:19,代码来源:rewrite_test.go
示例9: TestUnknownVar
func (s *RewriteSuite) TestUnknownVar(c *C) {
var outURL string
handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
outURL = rawURL(req)
w.Write([]byte("hello"))
})
rh, err := newRewriteHandler(handler,
&Rewrite{"^http://localhost/(foo)/(bar)$", `http://localhost/$1/{{.Bad}}/$2`, false, false})
c.Assert(rh, NotNil)
c.Assert(err, IsNil)
srv := httptest.NewServer(rh)
defer srv.Close()
re, _, err := testutils.Get(srv.URL+"/foo/bar", testutils.Host("localhost"))
c.Assert(err, IsNil)
c.Assert(re.StatusCode, Equals, http.StatusInternalServerError)
}
开发者ID:vnadgir-ef,项目名称:vulcand,代码行数:19,代码来源:rewrite_test.go
示例10: TestContentLength
// TestContentLength makes sure Content-Length is re-calculated if body rewrite is enabled.
func (s *RewriteSuite) TestContentLength(c *C) {
handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Length", "45")
w.WriteHeader(200)
w.Write([]byte(`{"foo": "{{.Request.Header.Get "X-Header"}}"}`))
})
rh, err := newRewriteHandler(handler, &Rewrite{"", "", true, false})
c.Assert(rh, NotNil)
c.Assert(err, IsNil)
srv := httptest.NewServer(rh)
defer srv.Close()
re, _, _ := testutils.Get(srv.URL,
testutils.Host("localhost"),
testutils.Header("X-Header", "bar"))
c.Assert(re.Header.Get("Content-Length"), Equals, "14")
}
开发者ID:vnadgir-ef,项目名称:vulcand,代码行数:21,代码来源:rewrite_test.go
示例11: TestRewriteScheme
// What real-world scenario does this test?
func (s *RewriteSuite) TestRewriteScheme(c *C) {
var outURL *url.URL
handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
outURL = req.URL
w.Write([]byte("hello"))
})
rh, err := newRewriteHandler(handler, &Rewrite{"^https://localhost/(foo)/(bar)$", "http://localhost/$1/$2", false, false})
c.Assert(rh, NotNil)
c.Assert(err, IsNil)
srv := httptest.NewUnstartedServer(rh)
srv.StartTLS()
defer srv.Close()
re, _, err := testutils.Get(srv.URL+"/foo/bar", testutils.Host("localhost"))
c.Assert(err, IsNil)
c.Assert(re.StatusCode, Equals, http.StatusOK)
c.Assert(outURL.Scheme, Equals, "http")
c.Assert(outURL.Path, Equals, "/foo/bar")
c.Assert(outURL.Host, Equals, "localhost")
}
开发者ID:vnadgir-ef,项目名称:vulcand,代码行数:23,代码来源:rewrite_test.go
注:本文中的github.com/vulcand/oxy/testutils.Host函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论