本文整理匯總了Golang中github.com/cloudfoundry/gorouter/route_service.RouteServiceConfig.SetupRouteServiceRequest方法的典型用法代碼示例。如果您正苦於以下問題:Golang RouteServiceConfig.SetupRouteServiceRequest方法的具體用法?Golang RouteServiceConfig.SetupRouteServiceRequest怎麽用?Golang RouteServiceConfig.SetupRouteServiceRequest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry/gorouter/route_service.RouteServiceConfig
的用法示例。
在下文中一共展示了RouteServiceConfig.SetupRouteServiceRequest方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SetupProxyRequest
func SetupProxyRequest(source *http.Request, target *http.Request,
routeServiceArgs route_service.RouteServiceArgs,
routeServiceConfig *route_service.RouteServiceConfig) {
if source.Header.Get("X-Forwarded-Proto") == "" {
scheme := "http"
if source.TLS != nil {
scheme = "https"
}
target.Header.Set("X-Forwarded-Proto", scheme)
}
target.URL.Scheme = "http"
target.URL.Host = source.Host
target.URL.Opaque = source.RequestURI
target.URL.RawQuery = ""
setRequestXRequestStart(source)
sig := target.Header.Get(route_service.RouteServiceSignature)
if forwardingToRouteService(routeServiceArgs.UrlString, sig) {
// An endpoint has a route service and this request did not come from the service
routeServiceConfig.SetupRouteServiceRequest(target, routeServiceArgs)
} else if hasBeenToRouteService(routeServiceArgs.UrlString, sig) {
// Remove the headers since the backend should not see it
target.Header.Del(route_service.RouteServiceSignature)
target.Header.Del(route_service.RouteServiceMetadata)
}
}
示例2:
parsed, err := url.Parse(str)
Expect(err).NotTo(HaveOccurred())
rsArgs = route_service.RouteServiceArgs{
UrlString: str,
ParsedUrl: parsed,
Signature: "signature",
Metadata: "metadata",
ForwardedUrlRaw: "http://test.com/path/",
}
})
It("sets the signature and metadata headers", func() {
Expect(request.Header.Get(route_service.RouteServiceSignature)).To(Equal(""))
Expect(request.Header.Get(route_service.RouteServiceMetadata)).To(Equal(""))
config.SetupRouteServiceRequest(request, rsArgs)
Expect(request.Header.Get(route_service.RouteServiceSignature)).To(Equal("signature"))
Expect(request.Header.Get(route_service.RouteServiceMetadata)).To(Equal("metadata"))
})
It("sets the forwarded URL header", func() {
Expect(request.Header.Get(route_service.RouteServiceForwardedUrl)).To(Equal(""))
config.SetupRouteServiceRequest(request, rsArgs)
Expect(request.Header.Get(route_service.RouteServiceForwardedUrl)).To(Equal("http://test.com/path/"))
})
It("changes the request host and URL", func() {
config.SetupRouteServiceRequest(request, rsArgs)