示例#1
0
文件: proxy.go 项目: qinguoan/vulcan
func SetupProxyRequest(source *http.Request, target *http.Request,
	routeServiceArgs route_service.RouteServiceArgs,
	routeServiceConfig *route_service.RouteServiceConfig) {
	target.URL.Scheme = "http"
	target.URL.Host = source.Host
	target.URL.Opaque = source.RequestURI
	target.URL.RawQuery = ""

	setRequestXRequestStart(source)
	setRequestXVcapRequestId(source, nil)

	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)
	}
}
			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)