You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We may still change this, but in the client module, the signature
of the client.Opt changed to now include a non-exported type, which
means that we can't construct a custom option that is implemented
using client options:
docker#18 16.94 # github.com/docker/cli/cli/context/docker
docker#18 16.94 cli/context/docker/load.go:105:29: cannot use withHTTPClient(tlsConfig) (value of type func(*client.Client) error) as client.Opt value in argument to append
docker#18 16.94 cli/context/docker/load.go:152:6: cannot use c (variable of type *client.Client) as *client.clientConfig value in argument to client.WithHTTPClient(&http.Client{…})
We can consider exporting the `client.clientConfig` type (but keep its
fields non-exported), but for this use, we don't strictly need it, so
let's change the implementation to not having to depend on that.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit e7d14d9)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
"failed to parse custom headers from %s environment variable: value must be formatted as comma-separated key=value pairs",
193
+
envOverrideHTTPHeaders,
194
+
))
195
+
}
196
+
iflen(fields) ==0 {
197
+
returnnil, nil
198
+
}
207
199
208
-
ifk=="" {
209
-
returninvalidParameter(errors.Errorf(
210
-
`failed to set custom headers from %s environment variable: value contains a key=value pair with an empty key: '%s'`,
211
-
envOverrideHTTPHeaders, kv,
212
-
))
213
-
}
200
+
env:=map[string]string{}
201
+
for_, kv:=rangefields {
202
+
k, v, hasValue:=strings.Cut(kv, "=")
214
203
215
-
// We don't currently allow empty key=value pairs, and produce an error.
216
-
// This is something we could allow in future (e.g. to read value
217
-
// from an environment variable with the same name). In the meantime,
218
-
// produce an error to prevent users from depending on this.
219
-
if!hasValue {
220
-
returninvalidParameter(errors.Errorf(
221
-
`failed to set custom headers from %s environment variable: missing "=" in key=value pair: '%s'`,
222
-
envOverrideHTTPHeaders, kv,
223
-
))
224
-
}
204
+
// Only strip whitespace in keys; preserve whitespace in values.
205
+
k=strings.TrimSpace(k)
225
206
226
-
env[http.CanonicalHeaderKey(k)] =v
207
+
ifk=="" {
208
+
returnnil, invalidParameter(errors.Errorf(
209
+
`failed to set custom headers from %s environment variable: value contains a key=value pair with an empty key: '%s'`,
210
+
envOverrideHTTPHeaders, kv,
211
+
))
227
212
}
228
213
229
-
iflen(env) ==0 {
230
-
// We should probably not hit this case, as we don't skip values
231
-
// (only return errors), but we don't want to discard existing
232
-
// headers with an empty set.
233
-
returnnil
214
+
// We don't currently allow empty key=value pairs, and produce an error.
215
+
// This is something we could allow in future (e.g. to read value
216
+
// from an environment variable with the same name). In the meantime,
217
+
// produce an error to prevent users from depending on this.
218
+
if!hasValue {
219
+
returnnil, invalidParameter(errors.Errorf(
220
+
`failed to set custom headers from %s environment variable: missing "=" in key=value pair: '%s'`,
221
+
envOverrideHTTPHeaders, kv,
222
+
))
234
223
}
235
224
236
-
// TODO(thaJeztah): add a client.WithExtraHTTPHeaders() function to allow these headers to be _added_ to existing ones, instead of _replacing_
237
-
// see https://github.com/docker/cli/pull/5098#issuecomment-2147403871 (when updating, also update the WARNING in the function and env-var GoDoc)
238
-
returnclient.WithHTTPHeaders(env)(apiClient)
225
+
env[http.CanonicalHeaderKey(k)] =v
226
+
}
227
+
228
+
iflen(env) ==0 {
229
+
// We should probably not hit this case, as we don't skip values
230
+
// (only return errors), but we don't want to discard existing
231
+
// headers with an empty set.
232
+
returnnil, nil
239
233
}
234
+
235
+
// TODO(thaJeztah): add a client.WithExtraHTTPHeaders() function to allow these headers to be _added_ to existing ones, instead of _replacing_
236
+
// see https://github.com/docker/cli/pull/5098#issuecomment-2147403871 (when updating, also update the WARNING in the function and env-var GoDoc)
0 commit comments