Skip to content

Commit c54123f

Browse files
committed
#776 Fix request counter for webserver
1 parent d4f7488 commit c54123f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

core/proxy.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,10 @@ func NewWebserverProxy(hoverfly *Hoverfly) *goproxy.ProxyHttpServer {
140140

141141
w.Header().Set("Req", r.RequestURI)
142142
w.Header().Set("Resp", resp.Header.Get("Content-Length"))
143-
144143
w.WriteHeader(resp.StatusCode)
145144
w.Write([]byte(body))
145+
146+
hoverfly.Counter.Count(hoverfly.Cfg.GetMode())
146147
})
147148

148149
if hoverfly.Cfg.Verbose {

functional-tests/core/ft_webserver_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ var _ = Describe("When running Hoverfly as a webserver", func() {
4949

5050
Expect(response.Header).To(HaveKeyWithValue("Header", []string{"value1", "value2"}))
5151
})
52+
53+
It("and it should increment the usage counter", func() {
54+
request := sling.New().Get("http://localhost:" + hoverfly.GetProxyPort() + "/path1")
55+
functional_tests.DoRequest(request)
56+
57+
req := sling.New().Get("http://localhost:" + hoverfly.GetAdminPort() + "/api/v2/hoverfly/usage")
58+
res := functional_tests.DoRequest(req)
59+
Expect(res.StatusCode).To(Equal(200))
60+
modeJson, err := ioutil.ReadAll(res.Body)
61+
Expect(err).To(BeNil())
62+
Expect(modeJson).To(Equal([]byte(`{"usage":{"counters":{"capture":0,"diff":0,"modify":0,"simulate":1,"spy":0,"synthesize":0}}}`)))
63+
})
5264
})
5365

5466
Context("using POST", func() {

0 commit comments

Comments
 (0)