googleapis / googleapis/google-http-java-client

allow overriding HttpResponse.getContent to install download throttler

Aberta
#586 1 comentário 0 reações 0 responsáveis Ver no GitHub
type: feature request
Linguagem predominante
Java
Estrelas
1.4k
Forks
473
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

We need to throttle downloads from cloud storage in order to minimize GC disturbances during (data) reload. I was unable to find a clean way to do this via existing API. Instead, the following workaround was implemented which suffers from extending `HttpURLConnection`. Is it possible to provide a proper hook for intercepting `InputStream`?

```java
protected Storage installHttpThrottler(StorageOptions.Builder storageOptions) {
return storageOptions
.setTransportOptions(HttpTransportOptions.newBuilder().setHttpTransportFactory(new ThrottledHttpTransportFactory()).build())
.build()
.getService();
}
```

```java
class ThrottledHttpTransportFactory implements HttpTransportFactory {
public HttpTransport create() { return new NetHttpTransport.Builder().setConnectionFactory(new ThrottledConnectionFactory()).build(); }
}
```

```java
class ThrottledConnectionFactory extends DefaultConnectionFactory {
@Override
public HttpURLConnection openConnection(URL url) throws IOException {
return new ThrottledUrlConnection(super.openConnection(url), url);
}
}
```

```java
class ThrottledUrlConnection extends HttpURLConnection {
HttpURLConnection delegate;

ThrottledUrlConnection(HttpURLConnection delegate, URL url) {
super(url);
this.delegate = delegate;
}

@Override
public InputStream getInputStream() throws IOException {
return new ThrottledInputStream(delegate.getInputStream(), rateLimiter, throughputMeter);
}
// followed by a long list of overridden methods to redirect via 'delegate'
....
}
```

Guia de contribuição

Abrir o guia de contribuição

Direção de pesquisa

Comece rastreando o ponto de entrada HttpResponse.getContent e o fluxo existente de HttpTransportFactory e InputStream descrito na issue. Determine onde um hook de interceptação poderia ser exposto sem estender HttpURLConnection; considera-se concluído quando os chamadores de download puderem instalar throttling por meio de uma API compatível e o workaround não for mais necessário.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
java
Domínio
api, networking
Tipo de issue
Funcionalidade
Dificuldade
4/5
Tempo estimado
3-5 dias
Status de atividade
Estagnada
Clareza
Razoavelmente clara
Facilidade para iniciantes
30/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.