Skip to content

Commit

Permalink
update rest.Request signatures
Browse files Browse the repository at this point in the history
Kubernetes-commit: 510aa1b432499f752fbacb2abf7e19f73311cdad
  • Loading branch information
mikedanese authored and k8s-publishing-bot committed Jan 28, 2020
1 parent 5f8ab2b commit ae9f6b2
Showing 1 changed file with 6 additions and 36 deletions.
42 changes: 6 additions & 36 deletions rest/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ type HTTPClient interface {
// ResponseWrapper is an interface for getting a response.
// The response may be either accessed as a raw data (the whole output is put into memory) or as a stream.
type ResponseWrapper interface {
DoRaw() ([]byte, error)
Stream() (io.ReadCloser, error)
DoRaw(context.Context) ([]byte, error)
Stream(context.Context) (io.ReadCloser, error)
}

// RequestConstructionError is returned when there's an error assembling a request.
Expand Down Expand Up @@ -104,9 +104,6 @@ type Request struct {
// output
err error
body io.Reader

// This is only used for per-request timeouts, deadlines, and cancellations.
ctx context.Context
}

// NewRequest creates a new request helper object for accessing runtime.Objects on a server.
Expand Down Expand Up @@ -438,13 +435,6 @@ func (r *Request) Body(obj interface{}) *Request {
return r
}

// Context adds a context to the request. Contexts are only used for
// timeouts, deadlines, and cancellations.
func (r *Request) Context(ctx context.Context) *Request {
r.ctx = ctx
return r
}

// URL returns the current working URL.
func (r *Request) URL() *url.URL {
p := r.pathPrefix
Expand Down Expand Up @@ -566,12 +556,7 @@ func (r *Request) tryThrottle(ctx context.Context) error {

// Watch attempts to begin watching the requested location.
// Returns a watch.Interface, or an error.
func (r *Request) Watch() (watch.Interface, error) {
ctx := context.Background()
if r.ctx != nil {
ctx = r.ctx
}

func (r *Request) Watch(ctx context.Context) (watch.Interface, error) {
// We specifically don't want to rate limit watches, so we
// don't use r.rateLimiter here.
if r.err != nil {
Expand Down Expand Up @@ -658,12 +643,7 @@ func updateURLMetrics(req *Request, resp *http.Response, err error) {
// Returns io.ReadCloser which could be used for streaming of the response, or an error
// Any non-2xx http status code causes an error. If we get a non-2xx code, we try to convert the body into an APIStatus object.
// If we can, we return that as an error. Otherwise, we create an error that lists the http status and the content of the response.
func (r *Request) Stream() (io.ReadCloser, error) {
ctx := context.Background()
if r.ctx != nil {
ctx = r.ctx
}

func (r *Request) Stream(ctx context.Context) (io.ReadCloser, error) {
if r.err != nil {
return nil, r.err
}
Expand Down Expand Up @@ -875,12 +855,7 @@ func (r *Request) request(ctx context.Context, fn func(*http.Request, *http.Resp
// Error type:
// * If the server responds with a status: *errors.StatusError or *errors.UnexpectedObjectError
// * http.Client.Do errors are returned directly.
func (r *Request) Do() Result {
ctx := context.Background()
if r.ctx != nil {
ctx = r.ctx
}

func (r *Request) Do(ctx context.Context) Result {
var result Result
err := r.request(ctx, func(req *http.Request, resp *http.Response) {
result = r.transformResponse(resp, req)
Expand All @@ -892,12 +867,7 @@ func (r *Request) Do() Result {
}

// DoRaw executes the request but does not process the response body.
func (r *Request) DoRaw() ([]byte, error) {
ctx := context.Background()
if r.ctx != nil {
ctx = r.ctx
}

func (r *Request) DoRaw(ctx context.Context) ([]byte, error) {
var result Result
err := r.request(ctx, func(req *http.Request, resp *http.Response) {
result.body, result.err = ioutil.ReadAll(resp.Body)
Expand Down

0 comments on commit ae9f6b2

Please sign in to comment.