googleapis / googleapis/google-cloud-java
[google-auth-library-java] How to set a timeout for GoogleCredentials?
- 主要语言
- Java
- 星标
- 2.1k
- 派生
- 1.2k
- 平均合并
- 1 天 23 小时
- 30 天内合并 PR
- 157
描述
`GoogleCredentials` can be initialized with an optional `HttpTransportFactory`. But this doesn't provide any means of setting the connection and read timeout for the HTTP requests made by the credentials implementation. Is there a way to set these timeout values for `GoogleCredentials`?
More context: In the Google HTTP client, the recommended way to set timeouts is via an `HttpRequestInitializer` that gets passed into the `HttpRequestFactory`.
```
myTransport.createRequestFactory(new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest request) throws IOException {
request.setConnectTimeout(10000);
request.setReadTimeout(10000);
}
});
```
But currently there appears to be no way to specify a request initializer for `GoogleCredentials`. As a result, there's no simple way to configure the timeouts for the HTTP requests made by this implementation.
This is a somewhat critical issue, since `GoogleCredentials` get invoked before any other HTTP requests are made by the client. The default timeout settings of `GoogleCredentials` essentially mask and override any timeout values set in the client.
```
myTransport.createRequestFactory(new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest request) throws IOException {
credentials.initialize(request);
request.setConnectTimeout(10000);
request.setReadTimeout(10000);
}
});
```
In the above example you expect requests to timeout after 10 seconds. But because credentials are in the initializer chain, it won't timeout until 60s (the default).
贡献指南
调研方向
从 GoogleCredentials 及其 HttpTransportFactory 路径开始,然后检查 HttpRequestInitializer 如何应用于 HttpRequestFactory。只有当调用方能够为凭据 HTTP 请求配置连接超时和读取超时,且这些设置不会被凭据初始化器覆盖时,此更改才算完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- google-cloud, java
- 领域
- authentication
- Issue 类型
- 功能
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100