proxyObj.ServeHTTP(resp, req) Eventually(logger).Should(Say("error")) Eventually(logger).Should(Say("route-endpoint")) }) }) Context("Log response time", func() { It("logs response time for HTTP connections", func() { body := []byte("some body") req := test_util.NewRequest("GET", "some-app", "/", bytes.NewReader(body)) resp := httptest.NewRecorder() proxyObj.ServeHTTP(resp, req) Expect(fakeAccessLogger.LogCallCount()).To(Equal(1)) Expect(fakeAccessLogger.LogArgsForCall(0).FinishedAt).NotTo(Equal(time.Time{})) }) It("logs response time for TCP connections", func() { req := test_util.NewRequest("UPGRADE", "some-app", "/", nil) req.Header.Set("Upgrade", "tcp") req.Header.Set("Connection", "upgrade") resp := httptest.NewRecorder() proxyObj.ServeHTTP(resp, req) Expect(fakeAccessLogger.LogCallCount()).To(Equal(1)) Expect(fakeAccessLogger.LogArgsForCall(0).FinishedAt).NotTo(Equal(time.Time{})) }) It("logs response time for Web Socket connections", func() { req := test_util.NewRequest("UPGRADE", "some-app", "/", nil)
nextCalled = false }) AfterEach(func() { Expect(nextCalled).To(BeTrue(), "Expected the next handler to be called.") }) It("sets an access log record on the context", func() { handler.ServeHTTP(proxyWriter, req, nextHandler) alr := proxyWriter.Context().Value("AccessLogRecord") Expect(alr).ToNot(BeNil()) Expect(alr).To(BeAssignableToTypeOf(&schema.AccessLogRecord{})) }) It("logs the access log record after all subsequent handlers have run", func() { handler.ServeHTTP(proxyWriter, req, nextHandler) Expect(accessLogger.LogCallCount()).To(Equal(1)) alr := accessLogger.LogArgsForCall(0) Expect(alr.StartedAt).ToNot(BeZero()) Expect(alr.Request).To(Equal(req)) Expect(*alr.ExtraHeadersToLog).To(Equal(extraHeadersToLog)) Expect(alr.FinishedAt).ToNot(BeZero()) Expect(alr.RequestBytesReceived).To(Equal(13)) Expect(alr.BodyBytesSent).To(Equal(37)) }) })