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"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
@ -252,8 +253,9 @@ func (o *statusCode) RoundTrip(_ *http.Request) (*http.Response, error) {
|
||||||
|
|
||||||
type NopReadCloser struct{}
|
type NopReadCloser struct{}
|
||||||
|
|
||||||
|
// Read always returns EOF to signal end of input
|
||||||
func (nrc *NopReadCloser) Read(buf []byte) (int, error) {
|
func (nrc *NopReadCloser) Read(buf []byte) (int, error) {
|
||||||
return 0, nil
|
return 0, io.EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nrc *NopReadCloser) Close() error {
|
func (nrc *NopReadCloser) Close() error {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package ingress
|
package ingress
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
|
"net/http/httptest"
|
||||||
"net/url"
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -128,9 +130,16 @@ func TestStaticHTTPStatus(t *testing.T) {
|
||||||
resp, err := o.RoundTrip(nil)
|
resp, err := o.RoundTrip(nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
_, err = resp.Body.Read(buf)
|
_, err = resp.Body.Read(buf)
|
||||||
require.NoError(t, err)
|
require.Equal(t, io.EOF, err)
|
||||||
require.NoError(t, resp.Body.Close())
|
require.NoError(t, resp.Body.Close())
|
||||||
require.Equal(t, 404, resp.StatusCode)
|
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()
|
||||||
sendReq()
|
sendReq()
|
||||||
|
|
Loading…
Reference in New Issue