From 11f97d88dd65b9846a2f78afa31a2d77b4924b08 Mon Sep 17 00:00:00 2001 From: Dmitry Kropachev Date: Mon, 20 Feb 2023 12:53:33 -0400 Subject: [PATCH] make NewRequest accept string --- client.go | 9 +++++++++ client_test.go | 2 ++ 2 files changed, 11 insertions(+) diff --git a/client.go b/client.go index f40d241..0667a51 100644 --- a/client.go +++ b/client.go @@ -218,6 +218,15 @@ func getBodyReaderAndContentLength(rawBody interface{}) (ReaderFunc, int64, erro } contentLength = int64(len(buf)) + // If a regular string, we can read it over and over via new + // readers + case string: + buf := body + bodyReader = func() (io.Reader, error) { + return strings.NewReader(buf), nil + } + contentLength = int64(len(buf)) + // If a bytes.Buffer we can read the underlying byte slice over and // over case *bytes.Buffer: diff --git a/client_test.go b/client_test.go index b3f8e6d..bcfc0d0 100644 --- a/client_test.go +++ b/client_test.go @@ -127,6 +127,8 @@ func TestClient_Do(t *testing.T) { // io.ReadSeeker testClientDo(t, strings.NewReader(string(testBytes))) // io.Reader + testClientDo(t, string(testBytes)) + // io.Reader testClientDo(t, &custReader{}) }