當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。