Skip to content

Commit

Permalink
client: support host (#216)
Browse files Browse the repository at this point in the history
* client: support host

* client: change host to Request

* client: remove unused field

* client: add host option

* Update client/client.go

---------

Co-authored-by: Ivan <82358585+covain@users.noreply.github.com>
  • Loading branch information
liam-trust and covain authored Apr 11, 2023
1 parent 4f7b6db commit 3eb9338
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const defaultTimeout = 5 * time.Second
type Request struct {
BaseURL string
Headers map[string]string
Host string
HttpClient HTTPClient
HttpErrorHandler HttpErrorHandler

Expand Down Expand Up @@ -138,6 +139,13 @@ func WithExtraHeader(key, value string) Option {
}
}

func WithHost(host string) Option {
return func(request *Request) error {
request.Host = host
return nil
}
}

func WithExtraHeaders(headers map[string]string) Option {
return func(request *Request) error {
for k, v := range headers {
Expand Down
4 changes: 4 additions & 0 deletions client/client_execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ func (r *Request) constructHttpRequest(ctx context.Context, req *Req) (*http.Req
}

r.setRequestHeaders(request, req)

if r.Host != "" {
request.Host = r.Host
}
return request, nil
}

Expand Down

0 comments on commit 3eb9338

Please sign in to comment.