示例#1
0
func InstrumentedHandler(handler http.Handler) http.Handler {
	if autowiredEmitter == nil {
		return handler
	}

	return dropsonde.InstrumentedHandler(handler, autowiredEmitter)
}
	rw.WriteHeader(123)
}

var _ = Describe("InstrumentedHandler", func() {
	var fakeEmitter *fake.FakeEventEmitter
	var h http.Handler
	var req *http.Request

	var origin = "testHandler/41"

	BeforeEach(func() {
		fakeEmitter = fake.NewFakeEventEmitter(origin)

		var err error
		fh := FakeHandler{}
		h = dropsonde.InstrumentedHandler(fh, fakeEmitter)
		req, err = http.NewRequest("GET", "http://foo.example.com/", nil)
		Expect(err).ToNot(HaveOccurred())
		req.RemoteAddr = "127.0.0.1"
		req.Header.Set("User-Agent", "our-testing-client")
	})

	AfterEach(func() {
		dropsonde.GenerateUuid = uuid.NewV4
	})

	Describe("request ID", func() {
		It("should add it to the request", func() {
			h.ServeHTTP(httptest.NewRecorder(), req)
			Expect(req.Header.Get("X-CF-RequestID")).ToNot(BeEmpty())
		})