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

Addressing #7 #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
20 changes: 15 additions & 5 deletions fluent.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Request struct {
backoff *backoff.ExponentialBackOff
req *http.Request
proxy string
client *http.Client
}

func (f *Request) newClient() *http.Client {
Expand Down Expand Up @@ -190,6 +191,12 @@ func (f *Request) Proxy(p string) *Request {
return f
}

// Set a http.Client
func (f *Request) Client(c *http.Client) *Request {
f.client = c
return f
}

func doReq(f *Request, c *http.Client) error {
var reqErr error
f.req, reqErr = f.newRequest()
Expand Down Expand Up @@ -243,10 +250,13 @@ func (f *Request) do(c *http.Client) (*http.Response, error) {
// This function has to be called as the last thing,
// after setting the other properties
func (f *Request) Send() (*http.Response, error) {
c := *http.DefaultClient
if f.timeout != 0 {
nc := f.newClient()
c = *nc
var c *http.Client
if f.client == nil { // create http client obj if non-set
if f.timeout != 0 {
c = f.newClient()
}
} else {
c = f.client
}

if f.proxy != "" {
Expand All @@ -261,7 +271,7 @@ func (f *Request) Send() (*http.Response, error) {
}
}

res, err := f.do(&c)
res, err := f.do(c)
return res, err
}

Expand Down