1
0
Fork 0

Clean old

This commit is contained in:
Ludovic Fernandez 2019-03-18 11:30:07 +01:00 committed by Traefiker Bot
parent 9908137638
commit 72ffa91fe0
195 changed files with 83 additions and 37524 deletions

View file

@ -6,7 +6,7 @@ import (
"net"
"net/http"
"github.com/containous/traefik/old/middlewares"
"github.com/containous/traefik/pkg/middlewares"
)
var (

View file

@ -53,7 +53,7 @@ type Handler struct {
func WrapHandler(handler *Handler) alice.Constructor {
return func(next http.Handler) (http.Handler, error) {
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
handler.ServeHTTP(rw, req, next.ServeHTTP)
handler.ServeHTTP(rw, req, next)
}), nil
}
}
@ -140,7 +140,7 @@ func GetLogData(req *http.Request) *LogData {
return nil
}
func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request, next http.HandlerFunc) {
func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request, next http.Handler) {
now := time.Now().UTC()
core := CoreLogData{

View file

@ -67,7 +67,7 @@ func TestLogRotation(t *testing.T) {
writeDone := make(chan bool)
go func() {
for i := 0; i < iterations; i++ {
logHandler.ServeHTTP(recorder, req, next)
logHandler.ServeHTTP(recorder, req, http.HandlerFunc(next))
if i == iterations/2 {
halfDone <- true
}
@ -624,7 +624,7 @@ func doLogging(t *testing.T, config *types.AccessLog) {
},
}
logger.ServeHTTP(httptest.NewRecorder(), req, logWriterTestHandlerFunc)
logger.ServeHTTP(httptest.NewRecorder(), req, http.HandlerFunc(logWriterTestHandlerFunc))
}
func logWriterTestHandlerFunc(rw http.ResponseWriter, r *http.Request) {

View file

@ -11,10 +11,10 @@ import (
"strconv"
"strings"
"github.com/containous/traefik/old/types"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/middlewares"
"github.com/containous/traefik/pkg/tracing"
"github.com/containous/traefik/pkg/types"
"github.com/opentracing/opentracing-go/ext"
"github.com/sirupsen/logrus"
"github.com/vulcand/oxy/utils"

View file

@ -0,0 +1,71 @@
package pipelining
import (
"bufio"
"context"
"net"
"net/http"
"github.com/containous/traefik/pkg/middlewares"
)
const (
typeName = "Pipelining"
)
// pipelining returns a middleware
type pipelining struct {
next http.Handler
}
// New returns a new pipelining instance
func New(ctx context.Context, next http.Handler, name string) http.Handler {
middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
return &pipelining{
next: next,
}
}
func (p *pipelining) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
// https://github.com/golang/go/blob/3d59583836630cf13ec4bfbed977d27b1b7adbdc/src/net/http/server.go#L201-L218
if r.Method == http.MethodPut || r.Method == http.MethodPost {
p.next.ServeHTTP(rw, r)
} else {
p.next.ServeHTTP(&writerWithoutCloseNotify{rw}, r)
}
}
// writerWithoutCloseNotify helps to disable closeNotify
type writerWithoutCloseNotify struct {
W http.ResponseWriter
}
// Header returns the response headers.
func (w *writerWithoutCloseNotify) Header() http.Header {
return w.W.Header()
}
// Write writes the data to the connection as part of an HTTP reply.
func (w *writerWithoutCloseNotify) Write(buf []byte) (int, error) {
return w.W.Write(buf)
}
// WriteHeader sends an HTTP response header with the provided
// status code.
func (w *writerWithoutCloseNotify) WriteHeader(code int) {
w.W.WriteHeader(code)
}
// Flush sends any buffered data to the client.
func (w *writerWithoutCloseNotify) Flush() {
if f, ok := w.W.(http.Flusher); ok {
f.Flush()
}
}
// Hijack hijacks the connection.
func (w *writerWithoutCloseNotify) Hijack() (net.Conn, *bufio.ReadWriter, error) {
return w.W.(http.Hijacker).Hijack()
}

View file

@ -0,0 +1,70 @@
package pipelining
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
type recorderWithCloseNotify struct {
*httptest.ResponseRecorder
}
func (r *recorderWithCloseNotify) CloseNotify() <-chan bool {
panic("implement me")
}
func TestNew(t *testing.T) {
testCases := []struct {
desc string
HTTPMethod string
implementCloseNotifier bool
}{
{
desc: "should not implement CloseNotifier with GET method",
HTTPMethod: http.MethodGet,
implementCloseNotifier: false,
},
{
desc: "should implement CloseNotifier with PUT method",
HTTPMethod: http.MethodPut,
implementCloseNotifier: true,
},
{
desc: "should implement CloseNotifier with POST method",
HTTPMethod: http.MethodPost,
implementCloseNotifier: true,
},
{
desc: "should not implement CloseNotifier with GET method",
HTTPMethod: http.MethodHead,
implementCloseNotifier: false,
},
{
desc: "should not implement CloseNotifier with PROPFIND method",
HTTPMethod: "PROPFIND",
implementCloseNotifier: false,
},
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
nextHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, ok := w.(http.CloseNotifier)
assert.Equal(t, test.implementCloseNotifier, ok)
w.WriteHeader(http.StatusOK)
})
handler := New(context.Background(), nextHandler, "pipe")
req := httptest.NewRequest(test.HTTPMethod, "http://localhost", nil)
handler.ServeHTTP(&recorderWithCloseNotify{httptest.NewRecorder()}, req)
})
}
}