Skip to content

Commit 6e13db8

Browse files
Merge pull request #74 from danielgtaylor/empty-array-header
fix: prevent sending empty array header params
2 parents c8c2248 + 5a1f4ba commit 6e13db8

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

cli/operation.go

+14-5
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,24 @@ func (o Operation) command() *cobra.Command {
104104

105105
headers := http.Header{}
106106
for _, param := range o.HeaderParams {
107-
if reflect.ValueOf(flags[param.Name]).Elem().Interface() == param.Default {
107+
rv := reflect.ValueOf(flags[param.Name]).Elem()
108+
if rv.Interface() == param.Default {
108109
// No need to send the default value. Just skip it.
109110
continue
110111
}
111112

112-
if param.Default == nil && reflect.ValueOf(flags[param.Name]).Elem().IsZero() {
113-
// No explicit default, so the implied default is the zero value.
114-
// Again no need to send that default, so we skip.
115-
continue
113+
if param.Default == nil {
114+
if rv.IsZero() {
115+
// No explicit default, so the implied default is the zero value.
116+
// Again no need to send that default, so we skip.
117+
continue
118+
}
119+
120+
if rv.Kind() == reflect.Slice && rv.Len() == 0 {
121+
// IsZero() above fails for empty arrays, so if it's empty let's
122+
// ignore it.
123+
continue
124+
}
116125
}
117126

118127
for _, v := range param.Serialize(flags[param.Name]) {

0 commit comments

Comments
 (0)