Skip to content

Commit

Permalink
fix: stackoverflow in ReadFrom (#925)
Browse files Browse the repository at this point in the history
* fix stackoverflow in ReadFrom - failing test

* fix stackoverflow
  • Loading branch information
romainmenke authored Nov 27, 2023
1 parent a95ea5f commit 4c7f918
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion http/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (i *rwInterceptor) Header() http.Header {
}

func (i *rwInterceptor) ReadFrom(r io.Reader) (n int64, err error) {
return io.Copy(i, r)
return io.Copy(struct{ io.Writer }{i}, r)
}

func (i *rwInterceptor) Flush() {
Expand Down
5 changes: 5 additions & 0 deletions http/interceptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ func TestReadFrom(t *testing.T) {
t.Errorf("unexpected error: %v", err)
}

_, err = rw.(io.ReaderFrom).ReadFrom(struct{ io.Reader }{bytes.NewBuffer([]byte("hello world"))})
if err != nil {
t.Errorf("unexpected error: %v", err)
}

err = responseProcessor(tx, req)
if err != nil {
t.Errorf("unexpected error: %v", err)
Expand Down

0 comments on commit 4c7f918

Please sign in to comment.