@ -1,5 +1,5 @@
/ *
/ *
* MinIO Cloud Storage , ( C ) 2018 MinIO , Inc .
* MinIO Cloud Storage , ( C ) 2018 - 2019 MinIO , Inc .
*
*
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* you may not use this file except in compliance with the License .
@ -32,6 +32,7 @@ const defaultFlushInterval = time.Duration(100) * time.Millisecond
type Forwarder struct {
type Forwarder struct {
RoundTripper http . RoundTripper
RoundTripper http . RoundTripper
PassHost bool
PassHost bool
Logger func ( error )
// internal variables
// internal variables
rewriter * headerRewriter
rewriter * headerRewriter
@ -58,10 +59,20 @@ func (f *Forwarder) ServeHTTP(w http.ResponseWriter, inReq *http.Request) {
} ,
} ,
Transport : f . RoundTripper ,
Transport : f . RoundTripper ,
FlushInterval : defaultFlushInterval ,
FlushInterval : defaultFlushInterval ,
ErrorHandler : f . customErrHandler ,
}
}
revproxy . ServeHTTP ( w , outReq )
revproxy . ServeHTTP ( w , outReq )
}
}
// customErrHandler is originally implemented to avoid having the following error
// `http: proxy error: context canceled` printed by Golang
func ( f * Forwarder ) customErrHandler ( w http . ResponseWriter , r * http . Request , err error ) {
if f . Logger != nil && err != context . Canceled {
f . Logger ( err )
}
w . WriteHeader ( http . StatusBadGateway )
}
func ( f * Forwarder ) getURLFromRequest ( req * http . Request ) * url . URL {
func ( f * Forwarder ) getURLFromRequest ( req * http . Request ) * url . URL {
// If the Request was created by Go via a real HTTP request, RequestURI will
// If the Request was created by Go via a real HTTP request, RequestURI will
// contain the original query string. If the Request was created in code, RequestURI
// contain the original query string. If the Request was created in code, RequestURI