TUN-3505: Response body for status code origin returns EOF on Read
This commit is contained in:
parent
bc015995d8
commit
b00bfe8e0b
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
@ -252,8 +253,9 @@ func (o *statusCode) RoundTrip(_ *http.Request) (*http.Response, error) {
|
|||
|
||||
type NopReadCloser struct{}
|
||||
|
||||
// Read always returns EOF to signal end of input
|
||||
func (nrc *NopReadCloser) Read(buf []byte) (int, error) {
|
||||
return 0, nil
|
||||
return 0, io.EOF
|
||||
}
|
||||
|
||||
func (nrc *NopReadCloser) Close() error {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package ingress
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
@ -128,9 +130,16 @@ func TestStaticHTTPStatus(t *testing.T) {
|
|||
resp, err := o.RoundTrip(nil)
|
||||
require.NoError(t, err)
|
||||
_, err = resp.Body.Read(buf)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, io.EOF, err)
|
||||
require.NoError(t, resp.Body.Close())
|
||||
require.Equal(t, 404, resp.StatusCode)
|
||||
|
||||
resp, err = o.RoundTrip(nil)
|
||||
require.NoError(t, err)
|
||||
w := httptest.NewRecorder()
|
||||
n, err := io.Copy(w, resp.Body)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(0), n)
|
||||
}
|
||||
sendReq()
|
||||
sendReq()
|
||||
|
|
Loading…
Reference in New Issue