mirror of
https://github.com/kubernetes/client-go.git
synced 2025-07-04 02:37:39 +00:00
Allow passing request-timeout from NewRequest all the way down to actual request
Kubernetes-commit: 7da1002091f026d4a58c1639dd70e1310b1d8991
This commit is contained in:
parent
5e622f37cd
commit
a4f6f78b29
@ -222,9 +222,9 @@ func (c *RESTClient) Verb(verb string) *Request {
|
|||||||
backoff := c.createBackoffMgr()
|
backoff := c.createBackoffMgr()
|
||||||
|
|
||||||
if c.Client == nil {
|
if c.Client == nil {
|
||||||
return NewRequest(nil, verb, c.base, c.versionedAPIPath, c.contentConfig, c.serializers, backoff, c.Throttle)
|
return NewRequest(nil, verb, c.base, c.versionedAPIPath, c.contentConfig, c.serializers, backoff, c.Throttle, 0)
|
||||||
}
|
}
|
||||||
return NewRequest(c.Client, verb, c.base, c.versionedAPIPath, c.contentConfig, c.serializers, backoff, c.Throttle)
|
return NewRequest(c.Client, verb, c.base, c.versionedAPIPath, c.contentConfig, c.serializers, backoff, c.Throttle, c.Client.Timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Post begins a POST request. Short for c.Verb("POST").
|
// Post begins a POST request. Short for c.Verb("POST").
|
||||||
|
@ -107,7 +107,7 @@ func (c *RESTClient) request(verb string) *restclient.Request {
|
|||||||
serializers.StreamingSerializer = info.StreamSerializer.Serializer
|
serializers.StreamingSerializer = info.StreamSerializer.Serializer
|
||||||
serializers.Framer = info.StreamSerializer.Framer
|
serializers.Framer = info.StreamSerializer.Framer
|
||||||
}
|
}
|
||||||
return restclient.NewRequest(c, verb, &url.URL{Host: "localhost"}, c.VersionedAPIPath, config, serializers, nil, nil)
|
return restclient.NewRequest(c, verb, &url.URL{Host: "localhost"}, c.VersionedAPIPath, config, serializers, nil, nil, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *RESTClient) Do(req *http.Request) (*http.Response, error) {
|
func (c *RESTClient) Do(req *http.Request) (*http.Response, error) {
|
||||||
|
@ -112,7 +112,7 @@ type Request struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewRequest creates a new request helper object for accessing runtime.Objects on a server.
|
// NewRequest creates a new request helper object for accessing runtime.Objects on a server.
|
||||||
func NewRequest(client HTTPClient, verb string, baseURL *url.URL, versionedAPIPath string, content ContentConfig, serializers Serializers, backoff BackoffManager, throttle flowcontrol.RateLimiter) *Request {
|
func NewRequest(client HTTPClient, verb string, baseURL *url.URL, versionedAPIPath string, content ContentConfig, serializers Serializers, backoff BackoffManager, throttle flowcontrol.RateLimiter, timeout time.Duration) *Request {
|
||||||
if backoff == nil {
|
if backoff == nil {
|
||||||
glog.V(2).Infof("Not implementing request backoff strategy.")
|
glog.V(2).Infof("Not implementing request backoff strategy.")
|
||||||
backoff = &NoBackoff{}
|
backoff = &NoBackoff{}
|
||||||
@ -131,6 +131,7 @@ func NewRequest(client HTTPClient, verb string, baseURL *url.URL, versionedAPIPa
|
|||||||
serializers: serializers,
|
serializers: serializers,
|
||||||
backoffMgr: backoff,
|
backoffMgr: backoff,
|
||||||
throttle: throttle,
|
throttle: throttle,
|
||||||
|
timeout: timeout,
|
||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
case len(content.AcceptContentTypes) > 0:
|
case len(content.AcceptContentTypes) > 0:
|
||||||
|
@ -57,11 +57,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestNewRequestSetsAccept(t *testing.T) {
|
func TestNewRequestSetsAccept(t *testing.T) {
|
||||||
r := NewRequest(nil, "get", &url.URL{Path: "/path/"}, "", ContentConfig{}, Serializers{}, nil, nil)
|
r := NewRequest(nil, "get", &url.URL{Path: "/path/"}, "", ContentConfig{}, Serializers{}, nil, nil, 0)
|
||||||
if r.headers.Get("Accept") != "" {
|
if r.headers.Get("Accept") != "" {
|
||||||
t.Errorf("unexpected headers: %#v", r.headers)
|
t.Errorf("unexpected headers: %#v", r.headers)
|
||||||
}
|
}
|
||||||
r = NewRequest(nil, "get", &url.URL{Path: "/path/"}, "", ContentConfig{ContentType: "application/other"}, Serializers{}, nil, nil)
|
r = NewRequest(nil, "get", &url.URL{Path: "/path/"}, "", ContentConfig{ContentType: "application/other"}, Serializers{}, nil, nil, 0)
|
||||||
if r.headers.Get("Accept") != "application/other, */*" {
|
if r.headers.Get("Accept") != "application/other, */*" {
|
||||||
t.Errorf("unexpected headers: %#v", r.headers)
|
t.Errorf("unexpected headers: %#v", r.headers)
|
||||||
}
|
}
|
||||||
@ -86,7 +86,7 @@ func TestRequestSetsHeaders(t *testing.T) {
|
|||||||
config := defaultContentConfig()
|
config := defaultContentConfig()
|
||||||
config.ContentType = "application/other"
|
config.ContentType = "application/other"
|
||||||
serializers := defaultSerializers(t)
|
serializers := defaultSerializers(t)
|
||||||
r := NewRequest(server, "get", &url.URL{Path: "/path"}, "", config, serializers, nil, nil)
|
r := NewRequest(server, "get", &url.URL{Path: "/path"}, "", config, serializers, nil, nil, 0)
|
||||||
|
|
||||||
// Check if all "issue" methods are setting headers.
|
// Check if all "issue" methods are setting headers.
|
||||||
_ = r.Do()
|
_ = r.Do()
|
||||||
@ -341,7 +341,7 @@ func TestResultIntoWithNoBodyReturnsErr(t *testing.T) {
|
|||||||
|
|
||||||
func TestURLTemplate(t *testing.T) {
|
func TestURLTemplate(t *testing.T) {
|
||||||
uri, _ := url.Parse("http://localhost")
|
uri, _ := url.Parse("http://localhost")
|
||||||
r := NewRequest(nil, "POST", uri, "", ContentConfig{GroupVersion: &schema.GroupVersion{Group: "test"}}, Serializers{}, nil, nil)
|
r := NewRequest(nil, "POST", uri, "", ContentConfig{GroupVersion: &schema.GroupVersion{Group: "test"}}, Serializers{}, nil, nil, 0)
|
||||||
r.Prefix("pre1").Resource("r1").Namespace("ns").Name("nm").Param("p0", "v0")
|
r.Prefix("pre1").Resource("r1").Namespace("ns").Name("nm").Param("p0", "v0")
|
||||||
full := r.URL()
|
full := r.URL()
|
||||||
if full.String() != "http://localhost/pre1/namespaces/ns/r1/nm?p0=v0" {
|
if full.String() != "http://localhost/pre1/namespaces/ns/r1/nm?p0=v0" {
|
||||||
@ -403,7 +403,7 @@ func TestTransformResponse(t *testing.T) {
|
|||||||
{Response: &http.Response{StatusCode: 200, Body: ioutil.NopCloser(bytes.NewReader(invalid))}, Data: invalid},
|
{Response: &http.Response{StatusCode: 200, Body: ioutil.NopCloser(bytes.NewReader(invalid))}, Data: invalid},
|
||||||
}
|
}
|
||||||
for i, test := range testCases {
|
for i, test := range testCases {
|
||||||
r := NewRequest(nil, "", uri, "", defaultContentConfig(), defaultSerializers(t), nil, nil)
|
r := NewRequest(nil, "", uri, "", defaultContentConfig(), defaultSerializers(t), nil, nil, 0)
|
||||||
if test.Response.Body == nil {
|
if test.Response.Body == nil {
|
||||||
test.Response.Body = ioutil.NopCloser(bytes.NewReader([]byte{}))
|
test.Response.Body = ioutil.NopCloser(bytes.NewReader([]byte{}))
|
||||||
}
|
}
|
||||||
@ -554,7 +554,7 @@ func TestTransformResponseNegotiate(t *testing.T) {
|
|||||||
serializers.RenegotiatedDecoder = negotiator.invoke
|
serializers.RenegotiatedDecoder = negotiator.invoke
|
||||||
contentConfig := defaultContentConfig()
|
contentConfig := defaultContentConfig()
|
||||||
contentConfig.ContentType = test.ContentType
|
contentConfig.ContentType = test.ContentType
|
||||||
r := NewRequest(nil, "", uri, "", contentConfig, serializers, nil, nil)
|
r := NewRequest(nil, "", uri, "", contentConfig, serializers, nil, nil, 0)
|
||||||
if test.Response.Body == nil {
|
if test.Response.Body == nil {
|
||||||
test.Response.Body = ioutil.NopCloser(bytes.NewReader([]byte{}))
|
test.Response.Body = ioutil.NopCloser(bytes.NewReader([]byte{}))
|
||||||
}
|
}
|
||||||
@ -1480,7 +1480,7 @@ func TestAbsPath(t *testing.T) {
|
|||||||
{"/p1/api/p2", "/api/r1", "/api/", "/p1/api/p2/api/"},
|
{"/p1/api/p2", "/api/r1", "/api/", "/p1/api/p2/api/"},
|
||||||
} {
|
} {
|
||||||
u, _ := url.Parse("http://localhost:123" + tc.configPrefix)
|
u, _ := url.Parse("http://localhost:123" + tc.configPrefix)
|
||||||
r := NewRequest(nil, "POST", u, "", ContentConfig{GroupVersion: &schema.GroupVersion{Group: "test"}}, Serializers{}, nil, nil).Prefix(tc.resourcePrefix).AbsPath(tc.absPath)
|
r := NewRequest(nil, "POST", u, "", ContentConfig{GroupVersion: &schema.GroupVersion{Group: "test"}}, Serializers{}, nil, nil, 0).Prefix(tc.resourcePrefix).AbsPath(tc.absPath)
|
||||||
if r.pathPrefix != tc.wantsAbsPath {
|
if r.pathPrefix != tc.wantsAbsPath {
|
||||||
t.Errorf("test case %d failed, unexpected path: %q, expected %q", i, r.pathPrefix, tc.wantsAbsPath)
|
t.Errorf("test case %d failed, unexpected path: %q, expected %q", i, r.pathPrefix, tc.wantsAbsPath)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user