Resync oxy with original repository
This commit is contained in:
parent
da5e4a13bf
commit
bee8ebb00b
31 changed files with 650 additions and 808 deletions
38
vendor/github.com/vulcand/oxy/cbreaker/fallback.go
generated
vendored
38
vendor/github.com/vulcand/oxy/cbreaker/fallback.go
generated
vendored
|
@ -5,6 +5,9 @@ import (
|
|||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/vulcand/oxy/utils"
|
||||
)
|
||||
|
||||
type Response struct {
|
||||
|
@ -25,20 +28,31 @@ func NewResponseFallback(r Response) (*ResponseFallback, error) {
|
|||
}
|
||||
|
||||
func (f *ResponseFallback) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
if log.GetLevel() >= log.DebugLevel {
|
||||
logEntry := log.WithField("Request", utils.DumpHttpRequest(req))
|
||||
logEntry.Debug("vulcand/oxy/fallback/response: begin ServeHttp on request")
|
||||
defer logEntry.Debug("vulcand/oxy/fallback/response: competed ServeHttp on request")
|
||||
}
|
||||
|
||||
if f.r.ContentType != "" {
|
||||
w.Header().Set("Content-Type", f.r.ContentType)
|
||||
}
|
||||
w.Header().Set("Content-Length", strconv.Itoa(len(f.r.Body)))
|
||||
w.WriteHeader(f.r.StatusCode)
|
||||
w.Write(f.r.Body)
|
||||
_, err := w.Write(f.r.Body)
|
||||
if err != nil {
|
||||
log.Errorf("vulcand/oxy/fallback/response: failed to write response, err: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
type Redirect struct {
|
||||
URL string
|
||||
URL string
|
||||
PreservePath bool
|
||||
}
|
||||
|
||||
type RedirectFallback struct {
|
||||
u *url.URL
|
||||
r Redirect
|
||||
}
|
||||
|
||||
func NewRedirectFallback(r Redirect) (*RedirectFallback, error) {
|
||||
|
@ -46,11 +60,25 @@ func NewRedirectFallback(r Redirect) (*RedirectFallback, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &RedirectFallback{u: u}, nil
|
||||
return &RedirectFallback{u: u, r: r}, nil
|
||||
}
|
||||
|
||||
func (f *RedirectFallback) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
w.Header().Set("Location", f.u.String())
|
||||
if log.GetLevel() >= log.DebugLevel {
|
||||
logEntry := log.WithField("Request", utils.DumpHttpRequest(req))
|
||||
logEntry.Debug("vulcand/oxy/fallback/redirect: begin ServeHttp on request")
|
||||
defer logEntry.Debug("vulcand/oxy/fallback/redirect: competed ServeHttp on request")
|
||||
}
|
||||
|
||||
location := f.u.String()
|
||||
if f.r.PreservePath {
|
||||
location += req.URL.Path
|
||||
}
|
||||
|
||||
w.Header().Set("Location", location)
|
||||
w.WriteHeader(http.StatusFound)
|
||||
w.Write([]byte(http.StatusText(http.StatusFound)))
|
||||
_, err := w.Write([]byte(http.StatusText(http.StatusFound)))
|
||||
if err != nil {
|
||||
log.Errorf("vulcand/oxy/fallback/redirect: failed to write response, err: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue