mirror of
https://github.com/openfaas/faas.git
synced 2025-06-18 20:16:37 +00:00
Use write interceptor from faas-provider
We now have two write interceptors, with one moved into faas-provider. This commit makes the gateway use the new external package and deletes its own. Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alex@openfaas.com>
This commit is contained in:
committed by
Alex Ellis
parent
bc2eeff467
commit
1a00a55c77
57
gateway/vendor/github.com/openfaas/faas-provider/httputil/write_interceptor.go
generated
vendored
Normal file
57
gateway/vendor/github.com/openfaas/faas-provider/httputil/write_interceptor.go
generated
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
package httputil
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"net"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func NewHttpWriteInterceptor(w http.ResponseWriter) *HttpWriteInterceptor {
|
||||
return &HttpWriteInterceptor{w, 0}
|
||||
}
|
||||
|
||||
type HttpWriteInterceptor struct {
|
||||
http.ResponseWriter
|
||||
statusCode int
|
||||
}
|
||||
|
||||
func (c *HttpWriteInterceptor) Status() int {
|
||||
if c.statusCode == 0 {
|
||||
return http.StatusOK
|
||||
}
|
||||
return c.statusCode
|
||||
}
|
||||
|
||||
func (c *HttpWriteInterceptor) Header() http.Header {
|
||||
return c.ResponseWriter.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.ResponseWriter.WriteHeader(code)
|
||||
}
|
||||
|
||||
func (c *HttpWriteInterceptor) Flush() {
|
||||
fl := c.ResponseWriter.(http.Flusher)
|
||||
fl.Flush()
|
||||
}
|
||||
|
||||
func (c *HttpWriteInterceptor) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||
hj := c.ResponseWriter.(http.Hijacker)
|
||||
return hj.Hijack()
|
||||
}
|
||||
|
||||
func (c *HttpWriteInterceptor) CloseNotify() <-chan bool {
|
||||
notifier, ok := c.ResponseWriter.(http.CloseNotifier)
|
||||
if ok == false {
|
||||
return nil
|
||||
}
|
||||
return notifier.CloseNotify()
|
||||
}
|
12
gateway/vendor/github.com/openfaas/faas-provider/httputil/writers.go
generated
vendored
Normal file
12
gateway/vendor/github.com/openfaas/faas-provider/httputil/writers.go
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
package httputil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Errorf sets the response status code and write formats the provided message as the
|
||||
// response body
|
||||
func Errorf(w http.ResponseWriter, statusCode int, msg string, args ...interface{}) {
|
||||
http.Error(w, fmt.Sprintf(msg, args...), statusCode)
|
||||
}
|
Reference in New Issue
Block a user