Vendor main dependencies.
This commit is contained in:
parent
49a09ab7dd
commit
dd5e3fba01
2738 changed files with 1045689 additions and 0 deletions
38
vendor/github.com/vulcand/oxy/utils/handler.go
generated
vendored
Normal file
38
vendor/github.com/vulcand/oxy/utils/handler.go
generated
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ErrorHandler interface {
|
||||
ServeHTTP(w http.ResponseWriter, req *http.Request, err error)
|
||||
}
|
||||
|
||||
var DefaultHandler ErrorHandler = &StdHandler{}
|
||||
|
||||
type StdHandler struct {
|
||||
}
|
||||
|
||||
func (e *StdHandler) ServeHTTP(w http.ResponseWriter, req *http.Request, err error) {
|
||||
statusCode := http.StatusInternalServerError
|
||||
if e, ok := err.(net.Error); ok {
|
||||
if e.Timeout() {
|
||||
statusCode = http.StatusGatewayTimeout
|
||||
} else {
|
||||
statusCode = http.StatusBadGateway
|
||||
}
|
||||
} else if err == io.EOF {
|
||||
statusCode = http.StatusBadGateway
|
||||
}
|
||||
w.WriteHeader(statusCode)
|
||||
w.Write([]byte(http.StatusText(statusCode)))
|
||||
}
|
||||
|
||||
type ErrorHandlerFunc func(http.ResponseWriter, *http.Request, error)
|
||||
|
||||
// ServeHTTP calls f(w, r).
|
||||
func (f ErrorHandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request, err error) {
|
||||
f(w, r, err)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue