OLD | NEW |
1 /* | 1 /* |
2 Copyright 2013 Google Inc | 2 Copyright 2013 Google Inc |
3 | 3 |
4 Licensed under the Apache License, Version 2.0 (the "License"); | 4 Licensed under the Apache License, Version 2.0 (the "License"); |
5 you may not use this file except in compliance with the License. | 5 you may not use this file except in compliance with the License. |
6 You may obtain a copy of the License at | 6 You may obtain a copy of the License at |
7 | 7 |
8 http://www.apache.org/licenses/LICENSE-2.0 | 8 http://www.apache.org/licenses/LICENSE-2.0 |
9 | 9 |
10 Unless required by applicable law or agreed to in writing, software | 10 Unless required by applicable law or agreed to in writing, software |
11 distributed under the License is distributed on an "AS IS" BASIS, | 11 distributed under the License is distributed on an "AS IS" BASIS, |
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 See the License for the specific language governing permissions and | 13 See the License for the specific language governing permissions and |
14 limitations under the License. | 14 limitations under the License. |
15 */ | 15 */ |
16 | 16 |
17 using System; | |
18 using System.Collections.Generic; | |
19 using System.Linq; | |
20 using System.Net.Http; | 17 using System.Net.Http; |
21 using System.Text; | |
22 using System.Threading; | 18 using System.Threading; |
| 19 using System.Threading.Tasks; |
23 | 20 |
24 namespace Google.Apis.Http | 21 namespace Google.Apis.Http |
25 { | 22 { |
26 /// <summary> Argument class to <see cref="IHttpUnsuccessfulResponseHandler.
HandleResponse"/>.</summary> | 23 /// <summary>Argument class to <see cref="IHttpUnsuccessfulResponseHandler.H
andleResponseAsync"/>.</summary> |
27 public class HandleUnsuccessfulResponseArgs | 24 public class HandleUnsuccessfulResponseArgs |
28 { | 25 { |
29 /// <summary> Gets or sets the sent request.</summary> | 26 /// <summary>Gets or sets the sent request.</summary> |
30 public HttpRequestMessage Request { get; set; } | 27 public HttpRequestMessage Request { get; set; } |
31 | 28 |
32 /// <summary> Gets or sets the abnormal response.</summary> | 29 /// <summary>Gets or sets the abnormal response.</summary> |
33 public HttpResponseMessage Response { get; set; } | 30 public HttpResponseMessage Response { get; set; } |
34 | 31 |
35 /// <summary> Gets or sets the total number of tries to send the request
.</summary> | 32 /// <summary>Gets or sets the total number of tries to send the request.
</summary> |
36 public int TotalTries { get; set; } | 33 public int TotalTries { get; set; } |
37 | 34 |
38 /// <summary> Gets or sets the current failed try.</summary> | 35 /// <summary>Gets or sets the current failed try.</summary> |
39 public int CurrentFailedTry { get; set; } | 36 public int CurrentFailedTry { get; set; } |
40 | 37 |
41 /// <summary> Gets whether there will actually be a retry if the handler
returns <c>true</c>.</summary> | 38 /// <summary>Gets whether there will actually be a retry if the handler
returns <c>true</c>.</summary> |
42 public bool SupportsRetry | 39 public bool SupportsRetry |
43 { | 40 { |
44 get { return TotalTries - CurrentFailedTry > 0; } | 41 get { return TotalTries - CurrentFailedTry > 0; } |
45 } | 42 } |
46 | 43 |
47 /// <summary> Gets and sets the cancellation token which belongs to the
request.</summary> | 44 /// <summary>Gets and sets the cancellation token which belongs to the r
equest.</summary> |
48 public CancellationToken CancellationToken { get; set; } | 45 public CancellationToken CancellationToken { get; set; } |
49 } | 46 } |
50 | 47 |
51 /// <summary> | 48 /// <summary> |
52 /// Unsuccessful response handler which is invoked when an abnormal Http res
ponse is returned when sending an Http | 49 /// Unsuccessful response handler which is invoked when an abnormal HTTP res
ponse is returned when sending a HTTP |
53 /// request. | 50 /// request. |
54 /// </summary> | 51 /// </summary> |
55 public interface IHttpUnsuccessfulResponseHandler | 52 public interface IHttpUnsuccessfulResponseHandler |
56 { | 53 { |
57 /// <summary> | 54 /// <summary> |
58 /// Handles an abnormal response when sending an Http request.· | 55 /// Handles an abnormal response when sending a HTTP request.· |
59 /// A simple rule must be followed, if you modify the request object in
a way that the abnormal response can· | 56 /// A simple rule must be followed, if you modify the request object in
a way that the abnormal response can· |
60 /// be resolved, you must return <c>true</c>. | 57 /// be resolved, you must return <c>true</c>. |
61 /// </summary> | 58 /// </summary> |
62 /// <param name="args"> | 59 /// <param name="args"> |
63 /// Handle response argument which contains properties like the request,
the response, current failed try. | 60 /// Handle response argument which contains properties like the request,
the response, current failed try. |
64 /// </param> | 61 /// </param> |
65 /// <returns>Whether or not this handler has made a change that will req
uire the request to be resent</returns> | 62 /// <returns>Whether or not this handler has made a change that will req
uire the request to be resent</returns> |
66 bool HandleResponse(HandleUnsuccessfulResponseArgs args); | 63 Task<bool> HandleResponseAsync(HandleUnsuccessfulResponseArgs args); |
67 } | 64 } |
68 } | 65 } |
OLD | NEW |