Skip to content

Commit

Permalink
#776 Fix request counter for webserver
Browse files Browse the repository at this point in the history
  • Loading branch information
tommysitu committed Oct 24, 2018
1 parent d4f7488 commit c54123f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,10 @@ func NewWebserverProxy(hoverfly *Hoverfly) *goproxy.ProxyHttpServer {

w.Header().Set("Req", r.RequestURI)
w.Header().Set("Resp", resp.Header.Get("Content-Length"))

w.WriteHeader(resp.StatusCode)
w.Write([]byte(body))

hoverfly.Counter.Count(hoverfly.Cfg.GetMode())
})

if hoverfly.Cfg.Verbose {
Expand Down
12 changes: 12 additions & 0 deletions functional-tests/core/ft_webserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ var _ = Describe("When running Hoverfly as a webserver", func() {

Expect(response.Header).To(HaveKeyWithValue("Header", []string{"value1", "value2"}))
})

It("and it should increment the usage counter", func() {
request := sling.New().Get("http://localhost:" + hoverfly.GetProxyPort() + "/path1")
functional_tests.DoRequest(request)

req := sling.New().Get("http://localhost:" + hoverfly.GetAdminPort() + "/api/v2/hoverfly/usage")
res := functional_tests.DoRequest(req)
Expect(res.StatusCode).To(Equal(200))
modeJson, err := ioutil.ReadAll(res.Body)
Expect(err).To(BeNil())
Expect(modeJson).To(Equal([]byte(`{"usage":{"counters":{"capture":0,"diff":0,"modify":0,"simulate":1,"spy":0,"synthesize":0}}}`)))
})
})

Context("using POST", func() {
Expand Down

0 comments on commit c54123f

Please sign in to comment.