Skip to content

Commit

Permalink
Don't set blanks
Browse files Browse the repository at this point in the history
  • Loading branch information
earthboundkid committed Jul 12, 2024
1 parent 4154690 commit 73d4170
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions builder_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ func (rb *Builder) Param(key string, values ...string) *Builder {
}

// ParamOptional sets a query parameter on a Builder's URL
// only if it is not set by some other call to Param or ParamOptional.
// only if it is not set by some other call to Param or ParamOptional
// and one of the values is a non-blank string.
func (rb *Builder) ParamOptional(key string, values ...string) *Builder {
rb.ub.ParamOptional(key, values...)
return rb
Expand All @@ -131,7 +132,8 @@ func (rb *Builder) Header(key string, values ...string) *Builder {
}

// HeaderOptional sets a header on a request
// only if it has not already been set by another call to Header or HeaderOptional.
// only if it has not already been set by another call to Header or HeaderOptional
// and one of the values is a non-blank string.
func (rb *Builder) HeaderOptional(key string, values ...string) *Builder {
rb.rb.HeaderOptional(key, values...)
return rb
Expand Down
4 changes: 3 additions & 1 deletion core_req.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ func (rb *requestBuilder) Request(ctx context.Context, u *url.URL) (req *http.Re
}
}
for _, kv := range rb.headers {
if kv.optional && req.Header.Get(kv.key) == "" {
if kv.optional &&
req.Header.Get(kv.key) == "" &&
minitrue.Or(kv.values...) != "" {
req.Header[http.CanonicalHeaderKey(kv.key)] = kv.values
}
}
Expand Down
4 changes: 3 additions & 1 deletion core_url.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ func (ub *urlBuilder) URL() (u *url.URL, err error) {
}
}
for _, kv := range ub.params {
if kv.optional && q.Get(kv.key) == "" {
if kv.optional &&
q.Get(kv.key) == "" &&
minitrue.Or(kv.values...) != "" {
q[kv.key] = kv.values
}
}
Expand Down

0 comments on commit 73d4170

Please sign in to comment.