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

Delta Between Two Patch Sets: Src/GoogleApis/Apis/Http/HttpClientFactory.cs

Issue 13412046: Reimplement OAuth2 library - Step 1 (Closed) Base URL: https://google-api-dotnet-client.googlecode.com/hg/
Left Patch Set: minor Created 10 years, 6 months ago
Right Patch Set: minor Created 10 years, 6 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
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; 17 using System;
18 using System.Collections.Generic; 18 using System.Collections.Generic;
19 using System.Linq; 19 using System.Linq;
20 using System.Net.Http; 20 using System.Net.Http;
21 using System.Text; 21 using System.Text;
22 22
23 using Google.Apis.Logging; 23 using Google.Apis.Logging;
24 24
25 namespace Google.Apis.Http 25 namespace Google.Apis.Http
26 { 26 {
27 /// <summary> The default implementation of the HTTP client factory. </summa ry> 27 /// <summary> The default implementation of the HTTP client factory. </summa ry>
28 public class HttpClientFactory : IHttpClientFactory 28 public class HttpClientFactory : IHttpClientFactory
29 { 29 {
30 /// <summary> The class logger. </summary> 30 /// <summary>The class logger.</summary>
31 private static readonly ILogger Logger = ApplicationContext.Logger.ForTy pe<HttpClientFactory>(); 31 private static readonly ILogger Logger = ApplicationContext.Logger.ForTy pe<HttpClientFactory>();
32 32
33 public ConfigurableHttpClient CreateHttpClient(CreateHttpClientArgs args ) 33 public ConfigurableHttpClient CreateHttpClient(CreateHttpClientArgs args )
34 { 34 {
35 // create the handler 35 // Create the handler.
36 var handler = CreateHandler(args); 36 var handler = CreateHandler(args);
37 var configurableHandler = new ConfigurableMessageHandler(handler) 37 var configurableHandler = new ConfigurableMessageHandler(handler)
38 { 38 {
39 ApplicationName = args.ApplicationName 39 ApplicationName = args.ApplicationName
40 }; 40 };
41 41
42 // create the client 42 // Create the client.
43 var client = new ConfigurableHttpClient(configurableHandler); 43 var client = new ConfigurableHttpClient(configurableHandler);
44 foreach (var initializer in args.Initializers) 44 foreach (var initializer in args.Initializers)
45 { 45 {
46 initializer.Initialize(client); 46 initializer.Initialize(client);
47 } 47 }
48 48
49 return client; 49 return client;
50 } 50 }
51 51
52 /// <summary>· 52 /// <summary>·
53 /// Creates a HTTP message handler by the given arguments. Override this method to mock a message handler. 53 /// Creates a HTTP message handler by the given arguments. Override this method to mock a message handler.
54 /// </summary> 54 /// </summary>
55 protected virtual HttpMessageHandler CreateHandler(CreateHttpClientArgs args) 55 protected virtual HttpMessageHandler CreateHandler(CreateHttpClientArgs args)
56 { 56 {
57 var handler = new HttpClientHandler(); 57 var handler = new HttpClientHandler();
58 58
59 // if the framework supports redirect configuration, set it to false , because ConfigurableMessageHnalder· 59 // If the framework supports redirect configuration, set it to false , because ConfigurableMessageHnalder·
60 // handles redirect 60 // handles redirect.
61 if (handler.SupportsRedirectConfiguration) 61 if (handler.SupportsRedirectConfiguration)
62 { 62 {
63 handler.AllowAutoRedirect = false; 63 handler.AllowAutoRedirect = false;
64 } 64 }
65 65
66 // if the framework supports automatic decompression and GZip is ena bled, set automatic decompression 66 // If the framework supports automatic decompression and GZip is ena bled, set automatic decompression.
67 if (handler.SupportsAutomaticDecompression && args.GZipEnabled) 67 if (handler.SupportsAutomaticDecompression && args.GZipEnabled)
68 { 68 {
69 handler.AutomaticDecompression = System.Net.DecompressionMethods .GZip | 69 handler.AutomaticDecompression = System.Net.DecompressionMethods .GZip |
70 System.Net.DecompressionMethods.Deflate; 70 System.Net.DecompressionMethods.Deflate;
71 } 71 }
72 72
73 Logger.Debug("Handler was created. SupportsRedirectConfiguration={0} , SupportsAutomaticDecompression={1}", 73 Logger.Debug("Handler was created. SupportsRedirectConfiguration={0} , SupportsAutomaticDecompression={1}",
74 handler.SupportsRedirectConfiguration, handler.SupportsAutomatic Decompression); 74 handler.SupportsRedirectConfiguration, handler.SupportsAutomatic Decompression);
75 75
76 return handler; 76 return handler;
77 } 77 }
78 } 78 }
79 } 79 }
LEFTRIGHT

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