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

Side by Side Diff: Src/GoogleApis/Apis/Requests/ClientServiceRequest.cs

Issue 96320045: Issue 464: Error when setting an invalid etag (Closed) Base URL: https://google-api-dotnet-client.googlecode.com/hg/
Patch Set: minor Created 9 years, 10 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
« no previous file with comments | « Src/GoogleApis.Tests/Apis/Requests/ClientServiceRequestTest.cs ('k') | 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 /* 1 /*
2 Copyright 2011 Google Inc 2 Copyright 2011 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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 178
179 #endregion 179 #endregion
180 180
181 public HttpRequestMessage CreateRequest(Nullable<bool> overrideGZipEnabl ed = null) 181 public HttpRequestMessage CreateRequest(Nullable<bool> overrideGZipEnabl ed = null)
182 { 182 {
183 var builder = CreateBuilder(); 183 var builder = CreateBuilder();
184 var request = builder.CreateRequest(); 184 var request = builder.CreateRequest();
185 object body = GetBody(); 185 object body = GetBody();
186 request.SetRequestSerailizedContent(service, body, overrideGZipEnabl ed.HasValue 186 request.SetRequestSerailizedContent(service, body, overrideGZipEnabl ed.HasValue
187 ? overrideGZipEnabled.Value : service.GZipEnabled); 187 ? overrideGZipEnabled.Value : service.GZipEnabled);
188
189 AddETag(request); 188 AddETag(request);
190 return request; 189 return request;
191 } 190 }
192 191
193 /// <summary> 192 /// <summary>
194 /// Creates the <see cref="Google.Apis.Requests.RequestBuilder"/> which is used to generate a request. 193 /// Creates the <see cref="Google.Apis.Requests.RequestBuilder"/> which is used to generate a request.
195 /// </summary> 194 /// </summary>
196 /// <returns> 195 /// <returns>
197 /// A new builder instance which contains the HTTP method and the right Uri with its path and query parameters. 196 /// A new builder instance which contains the HTTP method and the right Uri with its path and query parameters.
198 /// </returns> 197 /// </returns>
(...skipping 27 matching lines...) Expand all
226 #region ETag 225 #region ETag
227 226
228 /// <summary> 227 /// <summary>
229 /// Adds the right ETag action (e.g. If-Match) header to the given HTTP request if the body contains ETag. 228 /// Adds the right ETag action (e.g. If-Match) header to the given HTTP request if the body contains ETag.
230 /// </summary> 229 /// </summary>
231 private void AddETag(HttpRequestMessage request) 230 private void AddETag(HttpRequestMessage request)
232 { 231 {
233 IDirectResponseSchema body = GetBody() as IDirectResponseSchema; 232 IDirectResponseSchema body = GetBody() as IDirectResponseSchema;
234 if (body != null && !string.IsNullOrEmpty(body.ETag)) 233 if (body != null && !string.IsNullOrEmpty(body.ETag))
235 { 234 {
235 var etag = body.ETag;
236 ETagAction action = ETagAction == ETagAction.Default ? GetDefaul tETagAction(HttpMethod) : ETagAction; 236 ETagAction action = ETagAction == ETagAction.Default ? GetDefaul tETagAction(HttpMethod) : ETagAction;
237 switch (action) 237 try
238 { 238 {
239 case ETagAction.IfMatch: 239 switch (action)
240 request.Headers.IfMatch.Add(new EntityTagHeaderValue(bod y.ETag)); 240 {
241 break; 241 case ETagAction.IfMatch:
242 case ETagAction.IfNoneMatch: 242 request.Headers.IfMatch.Add(new EntityTagHeaderValue (etag));
243 request.Headers.IfNoneMatch.Add(new EntityTagHeaderValue (body.ETag)); 243 break;
244 break; 244 case ETagAction.IfNoneMatch:
245 request.Headers.IfNoneMatch.Add(new EntityTagHeaderV alue(etag));
246 break;
247 }
248 }
249 // When ETag is invalid we are going to create a request anyway.
250 // See https://code.google.com/p/google-api-dotnet-client/issues /detail?id=464 for more details.
251 catch (FormatException ex)
252 {
253 Logger.Error(ex, "Can't set {0}. Etag is: {1}.", action, eta g);
245 } 254 }
246 } 255 }
247 } 256 }
248 257
249 /// <summary>Returns the default ETagAction for a specific HTTP verb.</s ummary> 258 /// <summary>Returns the default ETagAction for a specific HTTP verb.</s ummary>
250 [VisibleForTestOnly] 259 [VisibleForTestOnly]
251 internal static ETagAction GetDefaultETagAction(string httpMethod) 260 internal static ETagAction GetDefaultETagAction(string httpMethod)
252 { 261 {
253 switch (httpMethod) 262 switch (httpMethod)
254 { 263 {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 { 332 {
324 throw new GoogleApiException(service.Name, 333 throw new GoogleApiException(service.Name,
325 string.Format("Parameter \"{0}\" is missing", parameter. Name)); 334 string.Format("Parameter \"{0}\" is missing", parameter. Name));
326 } 335 }
327 } 336 }
328 } 337 }
329 338
330 #endregion 339 #endregion
331 } 340 }
332 } 341 }
OLDNEW
« no previous file with comments | « Src/GoogleApis.Tests/Apis/Requests/ClientServiceRequestTest.cs ('k') | no next file » | no next file with comments »

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