当前位置: 首页>>代码示例>>Golang>>正文


Golang ProxyHttpServer.OnRequest方法代码示例

本文整理汇总了Golang中github.com/elazarl/goproxy.ProxyHttpServer.OnRequest方法的典型用法代码示例。如果您正苦于以下问题:Golang ProxyHttpServer.OnRequest方法的具体用法?Golang ProxyHttpServer.OnRequest怎么用?Golang ProxyHttpServer.OnRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/elazarl/goproxy.ProxyHttpServer的用法示例。


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

示例1:

		It("connects using invalid URL", func() {
			errMsg := "Invalid consumerProxyFunc URL"
			consumerProxyFunc = func(*http.Request) (*url.URL, error) {
				return nil, errors.New(errMsg)
			}

			perform()

			var err error
			Eventually(errorChan).Should(Receive(&err))
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring(errMsg))
		})

		It("connects to a consumerProxyFunc server rejecting CONNECT requests", func() {
			goProxyHandler.OnRequest().HandleConnect(goproxy.AlwaysReject)

			perform()

			var err error
			Eventually(errorChan).Should(Receive(&err))
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("Error dialing traffic controller server"))
		})

		It("connects to a non-consumerProxyFunc server", func() {
			nonProxyServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
				http.Error(w, "Go away, I am not a consumerProxyFunc!", http.StatusBadRequest)
			}))
			consumerProxyFunc = func(*http.Request) (*url.URL, error) {
				return url.Parse(nonProxyServer.URL)
开发者ID:cwlbraa,项目名称:cf-acceptance-tests,代码行数:31,代码来源:consumer_proxy_test.go

示例2: 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))
}
开发者ID:BenPhegan,项目名称:goproxy,代码行数:5,代码来源:basic.go

示例3:

		Context("with a message in the trafficcontroller", func() {
			BeforeEach(func() {
				messagesToSend <- marshalMessage(createMessage("hello", 0))
			})

			It("connects using valid URL to running proxy server", func() {
				message := <-incoming
				Expect(message.GetLogMessage().GetMessage()).To(Equal([]byte("hello")))
			})
		})

		Context("with an auth proxy server", func() {
			BeforeEach(func() {
				goProxyHandler.OnRequest().HandleConnect(auth.BasicConnect("my_realm", func(user, passwd string) bool {
					return user == "user" && passwd == "password"
				}))
				proxy = func(*http.Request) (*url.URL, error) {
					proxyURL, err := url.Parse(testProxyServer.URL)
					proxyURL.User = url.UserPassword("user", "password")
					if err != nil {
						return nil, err
					}

					return proxyURL, nil
				}
				messagesToSend <- marshalMessage(createMessage("hello", 0))
			})

			It("connects successfully", func() {
				message := <-incoming
开发者ID:cloudfoundry,项目名称:v3-cli-plugin,代码行数:30,代码来源:consumer_proxy_test.go


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