Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch requests fail if response contains duplicate HTTP headers #548

Closed
erickoledadevrel opened this issue Jun 9, 2015 · 0 comments
Closed
Assignees
Milestone

Comments

@erickoledadevrel
Copy link
Contributor

A BatchRequest will fail if the HTTP responses in the batch contain duplicate HTTP headers, generating a stack trace like the one seen below:

System.AggregateException was unhandled
HResult=-2146233088
Message=One or more errors occurred.
Source=mscorlib
StackTrace:
at System.Threading.Tasks.Task.WaitAll(Task[] tasks, Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.WaitAll(Task[] tasks, Int32 millisecondsTimeout)
at System.Threading.Tasks.Task.WaitAll(Task[] tasks)
at CalendarQuickstart.Program.Main(String[] args) in c:\Users\ekoleda\Documents\Visual Studio 2013\Projects\ConsoleApplication2\ConsoleApplication2\Program.cs:line 64
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.ArgumentException
HResult=-2147024809
Message=An item with the same key has already been added.
Source=mscorlib
StackTrace:
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add) at System.Collections.Generic.Dictionary2.Add(TKey key, TValue value)
at Google.Apis.Requests.BatchRequest.ParseAsHttpResponse(String content) in c:\code\google.com\google-api-dotnet-client\default\Tools\Google.Apis.Release\bin\Debug\test\default\Src\GoogleApis\Apis\Requests\BatchRequest.cs:line 257
at Google.Apis.Requests.BatchRequest.d__3.MoveNext() in c:\code\google.com\google-api-dotnet-client\default\Tools\Google.Apis.Release\bin\Debug\test\default\Src\GoogleApis\Apis\Requests\BatchRequest.cs:line 204

Duplicate headers are allowed per the HTTP spec, and are equivalent to a single header with a comma-separated list of values:

http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2

The source of this exception is due to the fact that a Dictionary is used to hold the header keys and value, which assumes unique keys:

https://github.com/google/google-api-dotnet-client/blob/81354f5b081d46cbb36768d867044d11046afd7f/Src/GoogleApis/Apis/Requests/BatchRequest.cs#L257

@peleyal peleyal self-assigned this Jun 9, 2015
@peleyal peleyal added this to the 1.9.2 milestone Jun 9, 2015
peleyal added a commit that referenced this issue Jun 10, 2015
Fix for issue #548 - Batch requests fail if the response contains duplicate HTTP headers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants