Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(384)

Side by Side Diff: Src/GoogleApis/Apis/Http/BackOffHandler.cs

Issue 12566043: Issue 369: Change default behavior of an HTTP request (Closed) Base URL: https://google-api-dotnet-client.googlecode.com/hg/
Patch Set: Miceli review Created 10 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 22 matching lines...) Expand all
33 33
34 /// <summary> An initializer class to initialize a back-off handler. </s ummary> 34 /// <summary> An initializer class to initialize a back-off handler. </s ummary>
35 public class Initializer 35 public class Initializer
36 { 36 {
37 /// <summary> Gets the back-off policy used by this back-off handler . </summary> 37 /// <summary> Gets the back-off policy used by this back-off handler . </summary>
38 public IBackOff BackOff { get; private set; } 38 public IBackOff BackOff { get; private set; }
39 39
40 /// <summary>· 40 /// <summary>·
41 /// Gets or sets the maximum time span to wait. If the back-off inst ance returns a greater time span then· 41 /// Gets or sets the maximum time span to wait. If the back-off inst ance returns a greater time span then·
42 /// this value, this handler returns <c>false</c> to both <see cref= "HandleException"/> and· 42 /// this value, this handler returns <c>false</c> to both <see cref= "HandleException"/> and·
43 /// <see cref="HandleResponse"/>. Default value is 2 minutes per a r etry request. 43 /// <see cref="HandleResponse"/>. Default value is 5 seconds per a r etry request.
44 /// </summary> 44 /// </summary>
45 public TimeSpan MaxTimeSpan { get; set; } 45 public TimeSpan MaxTimeSpan { get; set; }
46 46
47 /// <summary>· 47 /// <summary>·
48 /// Gets or sets a delegate function which indicates if this back-of f handler should handle an abnormal· 48 /// Gets or sets a delegate function which indicates if this back-of f handler should handle an abnormal·
49 /// Http response. The default is <see cref="DefaultHandleUnsuccessf ulResponse"/>.· 49 /// Http response. The default is <see cref="DefaultHandleUnsuccessf ulResponse"/>.·
50 /// </summary> 50 /// </summary>
51 public Func<HttpResponseMessage, bool> HandleUnsuccessfulResponseFun c { get; set; } 51 public Func<HttpResponseMessage, bool> HandleUnsuccessfulResponseFun c { get; set; }
52 52
53 /// <summary>· 53 /// <summary>·
54 /// Gets or sets a delegate function which indicates if this back-of f handler should handle an exception.· 54 /// Gets or sets a delegate function which indicates if this back-of f handler should handle an exception.·
55 /// The default is <see cref="DefaultHandleException"/>.· 55 /// The default is <see cref="DefaultHandleException"/>.·
56 /// </summary> 56 /// </summary>
57 public Func<Exception, bool> HandleExceptionFunc { get; set; } 57 public Func<Exception, bool> HandleExceptionFunc { get; set; }
58 58
59 /// <summary> Default function which handles server errors (5xx). </ summary> 59 /// <summary> Default function which handles server errors (503). </ summary>
60 public static readonly Func<HttpResponseMessage, bool> DefaultHandle UnsuccessfulResponseFunc = 60 public static readonly Func<HttpResponseMessage, bool> DefaultHandle UnsuccessfulResponseFunc =
61 (r) => (int)r.StatusCode / 100 == 5; 61 (r) => (int)r.StatusCode == 503;
62 62
63 /// <summary>· 63 /// <summary>·
64 /// Default function which handles exception which aren't· 64 /// Default function which handles exception which aren't·
65 /// <seealso cref="System.Threading.Tasks.TaskCanceledException"/> o r· 65 /// <seealso cref="System.Threading.Tasks.TaskCanceledException"/> o r·
66 /// <seealso cref="System.OperationCanceledException"/>. Those excep tions represent a task or an operation 66 /// <seealso cref="System.OperationCanceledException"/>. Those excep tions represent a task or an operation
67 /// which was canceled and we shouldn't retry. 67 /// which was canceled and we shouldn't retry.
68 /// </summary> 68 /// </summary>
69 public static readonly Func<Exception, bool> DefaultHandleExceptionF unc = 69 public static readonly Func<Exception, bool> DefaultHandleExceptionF unc =
70 (ex) => !(ex is TaskCanceledException || ex is OperationCanceled Exception); 70 (ex) => !(ex is TaskCanceledException || ex is OperationCanceled Exception);
71 71
72 /// <summary> Constructs a new initializer by the given back-off. </ summary> 72 /// <summary> Constructs a new initializer by the given back-off. </ summary>
73 public Initializer(IBackOff backOff) 73 public Initializer(IBackOff backOff)
74 { 74 {
75 BackOff = backOff; 75 BackOff = backOff;
76 HandleExceptionFunc = DefaultHandleExceptionFunc; 76 HandleExceptionFunc = DefaultHandleExceptionFunc;
77 HandleUnsuccessfulResponseFunc = DefaultHandleUnsuccessfulRespon seFunc; 77 HandleUnsuccessfulResponseFunc = DefaultHandleUnsuccessfulRespon seFunc;
78 MaxTimeSpan = TimeSpan.FromMinutes(2); 78 MaxTimeSpan = TimeSpan.FromSeconds(5);
79 } 79 }
80 } 80 }
81 81
82 /// <summary> Gets the back-off policy used by this back-off handler. </ summary> 82 /// <summary> Gets the back-off policy used by this back-off handler. </ summary>
83 public IBackOff BackOff { get; private set; } 83 public IBackOff BackOff { get; private set; }
84 84
85 /// <summary>· 85 /// <summary>·
86 /// Gets the maximum time span to wait. If the back-off instance returns a greater time span, the handle method 86 /// Gets the maximum time span to wait. If the back-off instance returns a greater time span, the handle method
87 /// returns <c>false</c>. Default value is 2 minutes per a retry request . 87 /// returns <c>false</c>. Default value is 5 seconds per a retry request .
88 /// </summary> 88 /// </summary>
89 public TimeSpan MaxTimeSpan { get; private set; } 89 public TimeSpan MaxTimeSpan { get; private set; }
90 90
91 /// <summary>· 91 /// <summary>·
92 /// Gets a delegate function which indicates if this back-off handler sh ould handle an abnormal Http response.· 92 /// Gets a delegate function which indicates if this back-off handler sh ould handle an abnormal Http response.·
93 /// The default is <see cref="DefaultHandleUnsuccessfulResponse"/>.· 93 /// The default is <see cref="DefaultHandleUnsuccessfulResponse"/>.·
94 /// </summary> 94 /// </summary>
95 public Func<HttpResponseMessage, bool> HandleUnsuccessfulResponseFunc { get; private set; } 95 public Func<HttpResponseMessage, bool> HandleUnsuccessfulResponseFunc { get; private set; }
96 96
97 /// <summary>· 97 /// <summary>·
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 protected virtual void Wait(TimeSpan ts, CancellationToken cancellationT oken) 168 protected virtual void Wait(TimeSpan ts, CancellationToken cancellationT oken)
169 { 169 {
170 try 170 try
171 { 171 {
172 TaskEx.Delay(ts, cancellationToken).Wait(); 172 TaskEx.Delay(ts, cancellationToken).Wait();
173 } 173 }
174 catch (Exception) { } 174 catch (Exception) { }
175 } 175 }
176 } 176 }
177 } 177 }
OLDNEW
« no previous file with comments | « Src/GoogleApis/Apis/Authentication/DelegateAuthenticator.cs ('k') | Src/GoogleApis/Apis/Http/ConfigurableMessageHandler.cs » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b