use of org.gradle.internal.resource.transport.http.HttpClientResponse in project gradle by gradle.
the class HttpBuildCacheService method store.
@Override
public void store(BuildCacheKey key, final BuildCacheEntryWriter output) throws BuildCacheException {
final URI uri = root.resolve(key.getHashCode());
HttpPut httpPut = new HttpPut(uri);
if (useExpectContinue) {
httpPut.setHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE);
}
httpPut.addHeader(HttpHeaders.CONTENT_TYPE, BUILD_CACHE_CONTENT_TYPE);
requestCustomizer.customize(httpPut);
httpPut.setEntity(new AbstractHttpEntity() {
@Override
public boolean isRepeatable() {
return true;
}
@Override
public long getContentLength() {
return output.getSize();
}
@Override
public InputStream getContent() {
throw new UnsupportedOperationException();
}
@Override
public void writeTo(OutputStream outstream) throws IOException {
output.writeTo(outstream);
}
@Override
public boolean isStreaming() {
return false;
}
});
try (HttpClientResponse response = httpClientHelper.performHttpRequest(httpPut)) {
StatusLine statusLine = response.getStatusLine();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Response for PUT {}: {}", safeUri(uri), statusLine);
}
int statusCode = statusLine.getStatusCode();
if (!isHttpSuccess(statusCode)) {
String defaultMessage = String.format("Storing entry at '%s' response status %d: %s", safeUri(uri), statusCode, statusLine.getReasonPhrase());
throwHttpStatusCodeException(statusCode, defaultMessage);
}
} catch (ClientProtocolException e) {
throw wrap(e.getCause());
} catch (IOException e) {
throw wrap(e);
}
}
use of org.gradle.internal.resource.transport.http.HttpClientResponse in project gradle by gradle.
the class HttpBuildCacheService method load.
@Override
public boolean load(BuildCacheKey key, BuildCacheEntryReader reader) throws BuildCacheException {
final URI uri = root.resolve("./" + key.getHashCode());
HttpGet httpGet = new HttpGet(uri);
httpGet.addHeader(HttpHeaders.ACCEPT, BUILD_CACHE_CONTENT_TYPE + ", */*");
requestCustomizer.customize(httpGet);
try (HttpClientResponse response = httpClientHelper.performHttpRequest(httpGet)) {
StatusLine statusLine = response.getStatusLine();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Response for GET {}: {}", safeUri(uri), statusLine);
}
int statusCode = statusLine.getStatusCode();
if (isHttpSuccess(statusCode)) {
reader.readFrom(response.getContent());
return true;
} else if (statusCode == HttpStatus.SC_NOT_FOUND) {
return false;
} else {
String defaultMessage = String.format("Loading entry from '%s' response status %d: %s", safeUri(uri), statusCode, statusLine.getReasonPhrase());
return throwHttpStatusCodeException(statusCode, defaultMessage);
}
} catch (IOException e) {
throw wrap(e);
}
}
Aggregations