コード例 #1
0
ファイル: proxy.go プロジェクト: cloudfoundry/gorouter
func (p *proxy) lookup(request *http.Request) *route.Pool {
	requestPath := request.URL.EscapedPath()

	uri := route.Uri(hostWithoutPort(request) + requestPath)
	appInstanceHeader := request.Header.Get(router_http.CfAppInstance)
	if appInstanceHeader != "" {
		appId, appIndex, err := router_http.ValidateCfAppInstance(appInstanceHeader)

		if err != nil {
			p.logger.Error("invalid-app-instance-header", err)
			return nil
		} else {
			return p.registry.LookupWithInstance(uri, appId, appIndex)
		}
	}

	return p.registry.Lookup(uri)
}
コード例 #2
0
ファイル: headers_test.go プロジェクト: cloudfoundry/gorouter
			})
		})
	})

	Describe("ValidateCfAppInstance", func() {
		var (
			appInstanceHeader string
		)

		Context("when given a complete app instance header", func() {
			BeforeEach(func() {
				appInstanceHeader = "app-id:1"
			})

			It("returns the app id and app index", func() {
				appID, appIndex, err := commonhttp.ValidateCfAppInstance(appInstanceHeader)
				Expect(err).ToNot(HaveOccurred())
				Expect(appID).To(Equal("app-id"))
				Expect(appIndex).To(Equal("1"))
			})
		})

		Context("when given an incomplete app instance header", func() {
			BeforeEach(func() {
				appInstanceHeader = "app-id:"
			})

			It("returns an error", func() {
				_, _, err := commonhttp.ValidateCfAppInstance(appInstanceHeader)
				Expect(err).To(HaveOccurred())
			})