mirror of
https://github.com/minio/minio.git
synced 2024-12-24 06:05:55 -05:00
Return HTTP response error for malformed requests (#6517)
This commit is contained in:
parent
ec2295c3dc
commit
1e5ac39ff3
@ -35,6 +35,10 @@ import (
|
||||
|
||||
var sslRequiredErrMsg = []byte("HTTP/1.0 403 Forbidden\r\n\r\nSSL required")
|
||||
|
||||
var malformedErrMsgFn = func(data interface{}) string {
|
||||
return fmt.Sprintf("HTTP/1.0 400 Bad Request\r\n\r\n%s", data)
|
||||
}
|
||||
|
||||
// HTTP methods.
|
||||
var methods = []string{
|
||||
http.MethodGet,
|
||||
@ -263,6 +267,7 @@ func (listener *httpListener) start() {
|
||||
ctx := logger.SetReqInfo(context.Background(), reqInfo)
|
||||
logger.LogIf(ctx, err)
|
||||
}
|
||||
bufconn.Write([]byte(malformedErrMsgFn(err)))
|
||||
bufconn.Close()
|
||||
return
|
||||
}
|
||||
@ -272,8 +277,9 @@ func (listener *httpListener) start() {
|
||||
reqInfo := (&logger.ReqInfo{}).AppendTags("remoteAddr", bufconn.RemoteAddr().String())
|
||||
reqInfo.AppendTags("localAddr", bufconn.LocalAddr().String())
|
||||
ctx := logger.SetReqInfo(context.Background(), reqInfo)
|
||||
logger.LogIf(ctx, fmt.Errorf("malformed HTTP invalid HTTP method %s", method))
|
||||
|
||||
err = fmt.Errorf("malformed HTTP invalid HTTP method %s", method)
|
||||
logger.LogIf(ctx, err)
|
||||
bufconn.Write([]byte(malformedErrMsgFn(err)))
|
||||
bufconn.Close()
|
||||
return
|
||||
}
|
||||
|
@ -657,11 +657,11 @@ func TestHTTPListenerAcceptError(t *testing.T) {
|
||||
continue
|
||||
}
|
||||
|
||||
_, err = bufio.NewReader(conn).ReadString('\n')
|
||||
if err == nil {
|
||||
t.Errorf("Test %d: reply read: expected = EOF got = <nil>", i+1)
|
||||
} else if err.Error() != "EOF" {
|
||||
t.Errorf("Test %d: reply read: expected = EOF got = %v", i+1, err)
|
||||
s, err := bufio.NewReader(conn).ReadString('\n')
|
||||
if err != nil {
|
||||
t.Errorf("Test %d: reply read: expected = <nil>, got = %s", i+1, err)
|
||||
} else if !strings.Contains(s, "HTTP/1.0 400 Bad Request") {
|
||||
t.Errorf("Test %d: reply read: expected = 'HTTP/1.0 400 Bad Request' got = %s", i+1, s)
|
||||
}
|
||||
|
||||
conn.Close()
|
||||
|
Loading…
Reference in New Issue
Block a user