Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Side by Side Diff: common/lhttp/client.go

Issue 2567313002: common/lhttp: fix line wrapping of comment (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package lhttp 5 package lhttp
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "encoding/json" 9 "encoding/json"
10 "fmt" 10 "fmt"
(...skipping 22 matching lines...) Expand all
33 // responsible for closing the Request body, as per http.Request Body method 33 // responsible for closing the Request body, as per http.Request Body method
34 // documentation. 34 // documentation.
35 type RequestGen func() (*http.Request, error) 35 type RequestGen func() (*http.Request, error)
36 36
37 // NewRequest returns a retriable request. 37 // NewRequest returns a retriable request.
38 // 38 //
39 // The handler func is responsible for closing the response Body before 39 // The handler func is responsible for closing the response Body before
40 // returning. It should return retry.Error in case of retriable error, for 40 // returning. It should return retry.Error in case of retriable error, for
41 // example if a TCP connection is terminated while receiving the content. 41 // example if a TCP connection is terminated while receiving the content.
42 // 42 //
43 // If rFn is nil, NewRequest will use a default exponential backoff strategy onl y 43 // If rFn is nil, NewRequest will use a default exponential backoff strategy
44 // for transient errors. 44 // only for transient errors.
45 func NewRequest(ctx context.Context, c *http.Client, rFn retry.Factory, rgen Req uestGen, handler Handler) func() (int, error) { 45 func NewRequest(ctx context.Context, c *http.Client, rFn retry.Factory, rgen Req uestGen, handler Handler) func() (int, error) {
46 if rFn == nil { 46 if rFn == nil {
47 rFn = retry.TransientOnly(retry.Default) 47 rFn = retry.TransientOnly(retry.Default)
48 } 48 }
49 49
50 return func() (int, error) { 50 return func() (int, error) {
51 status, attempts := 0, 0 51 status, attempts := 0, 0
52 err := retry.Retry(ctx, rFn, func() error { 52 err := retry.Retry(ctx, rFn, func() error {
53 attempts++ 53 attempts++
54 req, err := rgen() 54 req, err := rgen()
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 } 153 }
154 154
155 // PostJSON is a shorthand. It returns the HTTP status code and error if any. 155 // PostJSON is a shorthand. It returns the HTTP status code and error if any.
156 func PostJSON(ctx context.Context, rFn retry.Factory, c *http.Client, url string , headers map[string]string, in, out interface{}) (int, error) { 156 func PostJSON(ctx context.Context, rFn retry.Factory, c *http.Client, url string , headers map[string]string, in, out interface{}) (int, error) {
157 req, err := NewRequestJSON(ctx, c, rFn, url, "POST", headers, in, out) 157 req, err := NewRequestJSON(ctx, c, rFn, url, "POST", headers, in, out)
158 if err != nil { 158 if err != nil {
159 return 0, err 159 return 0, err
160 } 160 }
161 return req() 161 return req()
162 } 162 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698