1
0
Fork 0

chore: update linter.

This commit is contained in:
Ludovic Fernandez 2020-11-06 09:26:03 +01:00 committed by GitHub
parent f5b290b093
commit 267d0b7b5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 68 additions and 38 deletions

View file

@ -81,13 +81,13 @@ func (m *Mirroring) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
logger := log.FromContext(req.Context())
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)+
fmt.Sprintf("error creating reusable request: %v", err), http.StatusInternalServerError)
return
}
if err == errBodyTooLarge {
if errors.Is(err, errBodyTooLarge) {
req.Body = ioutil.NopCloser(io.MultiReader(bytes.NewReader(bytesRead), req.Body))
m.handler.ServeHTTP(rw, req)
logger.Debugf("no mirroring, request body larger than allowed size")
@ -196,13 +196,13 @@ func newReusableRequest(req *http.Request, maxBodySize int64) (*reusableRequest,
// the request body is larger than what we allow for the mirrors.
body := make([]byte, maxBodySize+1)
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
}
// we got an ErrUnexpectedEOF, which means there was less than maxBodySize data to read,
// which permits us sending also to all the mirrors later.
if err == io.ErrUnexpectedEOF {
if errors.Is(err, io.ErrUnexpectedEOF) {
return &reusableRequest{
req: req,
body: body[:n],

View file

@ -2,6 +2,7 @@ package wrr
import (
"container/heap"
"errors"
"fmt"
"net/http"
"sync"
@ -105,7 +106,7 @@ func (b *Balancer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
if b.stickyCookie != nil {
cookie, err := req.Cookie(b.stickyCookie.name)
if err != nil && err != http.ErrNoCookie {
if err != nil && !errors.Is(err, http.ErrNoCookie) {
log.WithoutContext().Warnf("Error while reading cookie: %v", err)
}

View file

@ -2,6 +2,7 @@ package service
import (
"context"
"errors"
"fmt"
"io"
"net"
@ -83,13 +84,14 @@ func buildProxy(passHostHeader *bool, responseForwarding *dynamic.ResponseForwar
statusCode := http.StatusInternalServerError
switch {
case err == io.EOF:
case errors.Is(err, io.EOF):
statusCode = http.StatusBadGateway
case err == context.Canceled:
case errors.Is(err, context.Canceled):
statusCode = StatusClientClosedRequest
default:
if e, ok := err.(net.Error); ok {
if e.Timeout() {
var netErr net.Error
if errors.As(err, &netErr) {
if netErr.Timeout() {
statusCode = http.StatusGatewayTimeout
} else {
statusCode = http.StatusBadGateway

View file

@ -3,6 +3,7 @@ package service
import (
"bufio"
"crypto/tls"
"errors"
"fmt"
"net"
"net/http"
@ -49,12 +50,13 @@ func TestWebSocketTCPClose(t *testing.T) {
withPath("/ws"),
).open()
require.NoError(t, err)
conn.Close()
serverErr := <-errChan
wsErr, ok := serverErr.(*gorillawebsocket.CloseError)
assert.Equal(t, true, ok)
var wsErr *gorillawebsocket.CloseError
require.True(t, errors.As(serverErr, &wsErr))
assert.Equal(t, 1006, wsErr.Code)
}
@ -119,7 +121,7 @@ func TestWebSocketPingPong(t *testing.T) {
_, _, err = conn.ReadMessage()
if err != goodErr {
if !errors.Is(err, goodErr) {
require.NoError(t, err)
}
}