コード例 #1
0
ファイル: proxy.go プロジェクト: sunatthegilddotcom/gorouter
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
0
			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)