mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-15 22:58:24 +00:00
Fall back to JSON request encoding after CBOR 415.
If a client is configured to encode request bodies to CBOR, but the server does not support CBOR, the server will respond with HTTP 415 (Unsupported Media Type). By feeding this response back to the RESTClient, subsequent requests can fall back to JSON, which is assumed to be acceptable. Kubernetes-commit: 1745dfdd154b1a838765e70b81c861c644bfcffe
This commit is contained in:
committed by
Kubernetes Publisher
parent
b3f6edec9a
commit
15af21a2ae
@@ -156,7 +156,7 @@ func NewRequest(c *RESTClient) *Request {
|
||||
timeout = c.Client.Timeout
|
||||
}
|
||||
|
||||
contentConfig := c.content
|
||||
contentConfig := c.content.GetClientContentConfig()
|
||||
contentTypeNotSet := len(contentConfig.ContentType) == 0
|
||||
if contentTypeNotSet {
|
||||
contentConfig.ContentType = "application/json"
|
||||
@@ -188,7 +188,7 @@ func NewRequestWithClient(base *url.URL, versionedAPIPath string, content Client
|
||||
return NewRequest(&RESTClient{
|
||||
base: base,
|
||||
versionedAPIPath: versionedAPIPath,
|
||||
content: content,
|
||||
content: requestClientContentConfigProvider{base: content},
|
||||
Client: client,
|
||||
})
|
||||
}
|
||||
@@ -1235,6 +1235,9 @@ func (r *Request) request(ctx context.Context, fn func(*http.Request, *http.Resp
|
||||
if req.ContentLength >= 0 && !(req.Body != nil && req.ContentLength == 0) {
|
||||
metrics.RequestSize.Observe(ctx, r.verb, r.URL().Host, float64(req.ContentLength))
|
||||
}
|
||||
if resp != nil && resp.StatusCode == http.StatusUnsupportedMediaType {
|
||||
r.c.content.UnsupportedMediaType(resp.Request.Header.Get("Content-Type"))
|
||||
}
|
||||
retry.After(ctx, r, resp, err)
|
||||
|
||||
done := func() bool {
|
||||
|
Reference in New Issue
Block a user