Fix issue with provider metrics

https://github.com/openfaas/faas-provider/pull/66

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
Alex Ellis (OpenFaaS Ltd)
2022-08-17 20:33:58 +01:00
parent 6dbc33d045
commit 9564e64980
5 changed files with 14 additions and 11 deletions

View File

@ -12,14 +12,14 @@ func NewHttpWriteInterceptor(w http.ResponseWriter) *HttpWriteInterceptor {
type HttpWriteInterceptor struct {
http.ResponseWriter
StatusCode int
statusCode int
}
func (c *HttpWriteInterceptor) Status() int {
if c.StatusCode == 0 {
if c.statusCode == 0 {
return http.StatusOK
}
return c.StatusCode
return c.statusCode
}
func (c *HttpWriteInterceptor) Header() http.Header {
@ -27,11 +27,14 @@ func (c *HttpWriteInterceptor) Header() http.Header {
}
func (c *HttpWriteInterceptor) Write(data []byte) (int, error) {
if c.statusCode == 0 {
c.WriteHeader(http.StatusOK)
}
return c.ResponseWriter.Write(data)
}
func (c *HttpWriteInterceptor) WriteHeader(code int) {
c.StatusCode = code
c.statusCode = code
c.ResponseWriter.WriteHeader(code)
}