1
0
mirror of https://github.com/containous/traefik.git synced 2024-10-27 01:55:17 +03:00

refactor: minor changes.

This commit is contained in:
Fernandez Ludovic 2017-08-24 00:59:59 +02:00 committed by Traefiker
parent f1a257abf8
commit 8235cd3645
2 changed files with 4 additions and 2 deletions

View File

@ -80,7 +80,7 @@ func (r *responseRecorder) Flush() {
func (s *StatsRecorder) ServeHTTP(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) { func (s *StatsRecorder) ServeHTTP(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
recorder := &responseRecorder{w, http.StatusOK} recorder := &responseRecorder{w, http.StatusOK}
next(recorder, r) next(recorder, r)
if recorder.statusCode >= 400 { if recorder.statusCode >= http.StatusBadRequest {
s.mutex.Lock() s.mutex.Lock()
defer s.mutex.Unlock() defer s.mutex.Unlock()
s.recentErrors = append([]*statsError{ s.recentErrors = append([]*statsError{

View File

@ -93,12 +93,13 @@ func TestStripPrefix(t *testing.T) {
t.Run(test.desc, func(t *testing.T) { t.Run(test.desc, func(t *testing.T) {
t.Parallel() t.Parallel()
var actualPath, actualHeader string var actualPath, actualHeader, requestURI string
handler := &StripPrefix{ handler := &StripPrefix{
Prefixes: test.prefixes, Prefixes: test.prefixes,
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
actualPath = r.URL.Path actualPath = r.URL.Path
actualHeader = r.Header.Get(ForwardedPrefixHeader) actualHeader = r.Header.Get(ForwardedPrefixHeader)
requestURI = r.RequestURI
}), }),
} }
@ -110,6 +111,7 @@ func TestStripPrefix(t *testing.T) {
assert.Equal(t, test.expectedStatusCode, resp.Code, "Unexpected status code.") assert.Equal(t, test.expectedStatusCode, resp.Code, "Unexpected status code.")
assert.Equal(t, test.expectedPath, actualPath, "Unexpected path.") assert.Equal(t, test.expectedPath, actualPath, "Unexpected path.")
assert.Equal(t, test.expectedHeader, actualHeader, "Unexpected '%s' header.", ForwardedPrefixHeader) assert.Equal(t, test.expectedHeader, actualHeader, "Unexpected '%s' header.", ForwardedPrefixHeader)
assert.Equal(t, test.expectedPath, requestURI, "Unexpected request URI.")
}) })
} }
} }