googleapis / googleapis/google-api-dotnet-client

Setting Version and VersionPolicy header on httpRequests

Open
#2,967 1 comment 0 reactions 0 assignees View on GitHub
priority: p3 type: feature request
Dominant language
C#
Stars
1.5k
Forks
558
Avg merge
16h 34m
Merged PRs (30d)
17

Description

By default, the http version used by Google is HTTP 1.1 ( I checked it by printing the response.Version) .
I have tried to set the version to 2.0 (as it has many advantages)

I was able to do it for Download request as below
```
var req = service.Files.Get(file.fileId);
req.ModifyRequest = AddHeader; //I set the Version and VersionPolicy on this callback.
var progress = await req.ExecuteAsStreamAsync DownloadAsync(fs);
```

But for batch request, if I set it on individual request, it is not getting honored.
```
BatchRequest _batch = new BatchRequest(service);
foreach (var file in files)
{
var request = service.Files.Get(file.fileId);
request.ModifyRequest = AddHeader;
request.Fields = "*";
_batch.Queue(request, response);
}
```

Setting it on HttpClient level also doesnt seem to get honored.

```
var service = new DriveService(new BaseClientService.Initializer()
{
HttpClientFactory = GetHttpClientFactory(),
HttpClientInitializer = ImpersonatedServiceCredential,
});
service.HttpClient.DefaultRequestVersion = new Version(2, 0); // Use HTTP/2
service.HttpClient.DefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrHigher;
```
Can you suggest how can I set the request version to 2.0 for all my requests ?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.