Updates for text streaming functions

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
Alex Ellis (OpenFaaS Ltd)
2024-01-11 18:13:34 +00:00
parent f17a25f3e8
commit 4a3fa684e2
59 changed files with 845 additions and 816 deletions

View File

@ -7,12 +7,17 @@ import (
)
func NewHttpWriteInterceptor(w http.ResponseWriter) *HttpWriteInterceptor {
return &HttpWriteInterceptor{w, 0}
return &HttpWriteInterceptor{
ResponseWriter: w,
statusCode: 0,
bytesWritten: 0,
}
}
type HttpWriteInterceptor struct {
http.ResponseWriter
statusCode int
statusCode int
bytesWritten int64
}
func (c *HttpWriteInterceptor) Status() int {
@ -22,6 +27,10 @@ func (c *HttpWriteInterceptor) Status() int {
return c.statusCode
}
func (c *HttpWriteInterceptor) BytesWritten() int64 {
return c.bytesWritten
}
func (c *HttpWriteInterceptor) Header() http.Header {
return c.ResponseWriter.Header()
}
@ -30,6 +39,9 @@ func (c *HttpWriteInterceptor) Write(data []byte) (int, error) {
if c.statusCode == 0 {
c.WriteHeader(http.StatusOK)
}
c.bytesWritten += int64(len(data))
return c.ResponseWriter.Write(data)
}