Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NewRawRequest #170

Merged
merged 2 commits into from
Oct 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion request.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ func (r Request) String() string {
return fmt.Sprintf("Request(%s %s://%s%s)", r.Method, r.URL.Scheme, r.Host, r.URL.Path)
}

// NewRequest constructs a new Request with the given parameters, and if non-nil, encodes the given body into it.
// NewRequest constructs a new Request with the given parameters. If the body is non-nil, it'll get encoded as JSON
// unless you pass in a raw io.ReadCloser or io.Reader
func NewRequest(ctx context.Context, method, url string, body interface{}) Request {
if ctx == nil {
ctx = context.Background()
Expand All @@ -255,3 +256,9 @@ func NewRequest(ctx context.Context, method, url string, body interface{}) Reque
}
return req
}

// NewRawRequest constructs a new Request with the given parameters and raw body
func NewRawRequest(ctx context.Context, method, url string, body io.ReadCloser) Request {
// as an io.ReadCloser, the body won't be encoded as JSON
return NewRequest(ctx, method, url, body)
}
Loading