@@ -22,6 +22,8 @@ import (
2222 "github.com/urfave/cli/v2"
2323 "golang.org/x/sync/errgroup"
2424
25+ "github.com/cloudflare/cloudflared/cfio"
26+
2527 "github.com/cloudflare/cloudflared/config"
2628 "github.com/cloudflare/cloudflared/connection"
2729 "github.com/cloudflare/cloudflared/hello"
@@ -62,6 +64,10 @@ func (w *mockHTTPRespWriter) WriteRespHeaders(status int, header http.Header) er
6264 return nil
6365}
6466
67+ func (w * mockHTTPRespWriter ) AddTrailer (trailerName , trailerValue string ) {
68+ // do nothing
69+ }
70+
6571func (w * mockHTTPRespWriter ) Read (data []byte ) (int , error ) {
6672 return 0 , fmt .Errorf ("mockHTTPRespWriter doesn't implement io.Reader" )
6773}
@@ -117,7 +123,10 @@ func newMockSSERespWriter() *mockSSERespWriter {
117123}
118124
119125func (w * mockSSERespWriter ) Write (data []byte ) (int , error ) {
120- w .writeNotification <- data
126+ newData := make ([]byte , len (data ))
127+ copy (newData , data )
128+
129+ w .writeNotification <- newData
121130 return len (data ), nil
122131}
123132
@@ -256,11 +265,8 @@ func testProxySSE(proxy connection.OriginProxy) func(t *testing.T) {
256265
257266 for i := 0 ; i < pushCount ; i ++ {
258267 line := responseWriter .ReadBytes ()
259- expect := fmt .Sprintf ("%d\n " , i )
268+ expect := fmt .Sprintf ("%d\n \n " , i )
260269 require .Equal (t , []byte (expect ), line , fmt .Sprintf ("Expect to read %v, got %v" , expect , line ))
261-
262- line = responseWriter .ReadBytes ()
263- require .Equal (t , []byte ("\n " ), line , fmt .Sprintf ("Expect to read '\n ', got %v" , line ))
264270 }
265271
266272 cancel ()
@@ -276,7 +282,7 @@ func testProxySSEAllData(proxy *Proxy) func(t *testing.T) {
276282 responseWriter := newMockSSERespWriter ()
277283
278284 // responseWriter uses an unbuffered channel, so we call in a different go-routine
279- go proxy . writeEventStream (responseWriter , eyeballReader )
285+ go cfio . Copy (responseWriter , eyeballReader )
280286
281287 result := string (<- responseWriter .writeNotification )
282288 require .Equal (t , "data\r \r " , result )
@@ -825,6 +831,10 @@ func (w *wsRespWriter) WriteRespHeaders(status int, header http.Header) error {
825831 return nil
826832}
827833
834+ func (w * wsRespWriter ) AddTrailer (trailerName , trailerValue string ) {
835+ // do nothing
836+ }
837+
828838// respHeaders is a test function to read respHeaders
829839func (w * wsRespWriter ) headers () http.Header {
830840 // Removing indeterminstic header because it cannot be asserted.
@@ -852,6 +862,10 @@ func (m *mockTCPRespWriter) Write(p []byte) (n int, err error) {
852862 return m .w .Write (p )
853863}
854864
865+ func (w * mockTCPRespWriter ) AddTrailer (trailerName , trailerValue string ) {
866+ // do nothing
867+ }
868+
855869func (m * mockTCPRespWriter ) WriteRespHeaders (status int , header http.Header ) error {
856870 m .responseHeaders = header
857871 m .code = status
0 commit comments