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

Delta Between Two Patch Sets: 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/
Left Patch Set: Created 10 years, 2 months ago
Right Patch Set: minor Created 10 years, 2 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
« no previous file with change/comment | « Src/GoogleApis.Tests/Apis/Requests/ClientServiceRequestTest.cs ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 <seealso cref="Google.Apis.Requests.RequestBuilder"/> wh ich 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>
199 private RequestBuilder CreateBuilder() 198 private RequestBuilder CreateBuilder()
200 { 199 {
201 var builder = new RequestBuilder() 200 var builder = new RequestBuilder()
202 { 201 {
203 BaseUri = new Uri(Service.BaseUri), 202 BaseUri = new Uri(Service.BaseUri),
204 Path = RestPath, 203 Path = RestPath,
(...skipping 22 matching lines...) Expand all
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 {
236 var etag = body.ETag; 235 var etag = body.ETag;
237 // Fix etag if it's invalid. 236 ETagAction action = ETagAction == ETagAction.Default ? GetDefaul tETagAction(HttpMethod) : ETagAction;
237 try
238 {
239 switch (action)
240 {
241 case ETagAction.IfMatch:
242 request.Headers.IfMatch.Add(new EntityTagHeaderValue (etag));
243 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.
238 // See https://code.google.com/p/google-api-dotnet-client/issues /detail?id=464 for more details. 250 // See https://code.google.com/p/google-api-dotnet-client/issues /detail?id=464 for more details.
239 if (!etag.StartsWith("\"")) 251 catch (FormatException ex)
240 etag = "\"" etag; 252 {
241 if (!etag.EndsWith("\"")) 253 Logger.Error(ex, "Can't set {0}. Etag is: {1}.", action, eta g);
242 etag = etag "\"";
243
244 ETagAction action = ETagAction == ETagAction.Default ? GetDefaul tETagAction(HttpMethod) : ETagAction;
245 switch (action)
246 {
247 case ETagAction.IfMatch:
248 request.Headers.IfMatch.Add(new EntityTagHeaderValue(eta g));
249 break;
250 case ETagAction.IfNoneMatch:
251 request.Headers.IfNoneMatch.Add(new EntityTagHeaderValue (etag));
252 break;
253 } 254 }
254 } 255 }
255 } 256 }
256 257
257 /// <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>
258 [VisibleForTestOnly] 259 [VisibleForTestOnly]
259 internal static ETagAction GetDefaultETagAction(string httpMethod) 260 internal static ETagAction GetDefaultETagAction(string httpMethod)
260 { 261 {
261 switch (httpMethod) 262 switch (httpMethod)
262 { 263 {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 { 332 {
332 throw new GoogleApiException(service.Name, 333 throw new GoogleApiException(service.Name,
333 string.Format("Parameter \"{0}\" is missing", parameter. Name)); 334 string.Format("Parameter \"{0}\" is missing", parameter. Name));
334 } 335 }
335 } 336 }
336 } 337 }
337 338
338 #endregion 339 #endregion
339 } 340 }
340 } 341 }
LEFTRIGHT

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