"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "pkg/server/service/loadbalancer/mirror/mirror.go" between
traefik-v2.3.2.src.tar.gz and traefik-v2.3.3.src.tar.gz

About: Traefik is a cloud native edge router, a reverse proxy and load balancer for HTTP and TCP-based applications.

mirror.go  (traefik-v2.3.2.src):mirror.go  (traefik-v2.3.3.src)
skipping to change at line 84 skipping to change at line 84
func (m *Mirroring) ServeHTTP(rw http.ResponseWriter, req *http.Request) { func (m *Mirroring) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
mirrors := m.getActiveMirrors() mirrors := m.getActiveMirrors()
if len(mirrors) == 0 { if len(mirrors) == 0 {
m.handler.ServeHTTP(rw, req) m.handler.ServeHTTP(rw, req)
return return
} }
logger := log.FromContext(req.Context()) logger := log.FromContext(req.Context())
rr, bytesRead, err := newReusableRequest(req, m.maxBodySize) rr, bytesRead, err := newReusableRequest(req, m.maxBodySize)
if err != nil && err != errBodyTooLarge { if err != nil && !errors.Is(err, errBodyTooLarge) {
http.Error(rw, http.StatusText(http.StatusInternalServerError)+ http.Error(rw, http.StatusText(http.StatusInternalServerError)+
fmt.Sprintf("error creating reusable request: %v", err), http.StatusInternalServerError) fmt.Sprintf("error creating reusable request: %v", err), http.StatusInternalServerError)
return return
} }
if err == errBodyTooLarge { if errors.Is(err, errBodyTooLarge) {
req.Body = ioutil.NopCloser(io.MultiReader(bytes.NewReader(bytesR ead), req.Body)) req.Body = ioutil.NopCloser(io.MultiReader(bytes.NewReader(bytesR ead), req.Body))
m.handler.ServeHTTP(rw, req) m.handler.ServeHTTP(rw, req)
logger.Debugf("no mirroring, request body larger than allowed siz e") logger.Debugf("no mirroring, request body larger than allowed siz e")
return return
} }
m.handler.ServeHTTP(rw, rr.clone(req.Context())) m.handler.ServeHTTP(rw, rr.clone(req.Context()))
select { select {
case <-req.Context().Done(): case <-req.Context().Done():
skipping to change at line 199 skipping to change at line 199
return &reusableRequest{ return &reusableRequest{
req: req, req: req,
body: body, body: body,
}, nil, nil }, nil, nil
} }
// we purposefully try to read _more_ than maxBodySize to detect whether // we purposefully try to read _more_ than maxBodySize to detect whether
// the request body is larger than what we allow for the mirrors. // the request body is larger than what we allow for the mirrors.
body := make([]byte, maxBodySize+1) body := make([]byte, maxBodySize+1)
n, err := io.ReadFull(req.Body, body) n, err := io.ReadFull(req.Body, body)
if err != nil && err != io.ErrUnexpectedEOF { if err != nil && !errors.Is(err, io.ErrUnexpectedEOF) {
return nil, nil, err return nil, nil, err
} }
// we got an ErrUnexpectedEOF, which means there was less than maxBodySiz e data to read, // we got an ErrUnexpectedEOF, which means there was less than maxBodySiz e data to read,
// which permits us sending also to all the mirrors later. // which permits us sending also to all the mirrors later.
if err == io.ErrUnexpectedEOF { if errors.Is(err, io.ErrUnexpectedEOF) {
return &reusableRequest{ return &reusableRequest{
req: req, req: req,
body: body[:n], body: body[:n],
}, nil, nil }, nil, nil
} }
// err == nil , which means data size > maxBodySize // err == nil , which means data size > maxBodySize
return nil, body[:n], errBodyTooLarge return nil, body[:n], errBodyTooLarge
} }
 End of changes. 4 change blocks. 
4 lines changed or deleted 4 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)