use of com.google.api.client.http.HttpHeaders in project scout.rt by eclipse.
the class HttpProxy method writeRequestHeaders.
protected void writeRequestHeaders(HttpServletRequest req, HttpRequest httpReq) {
Enumeration<String> headerNames = req.getHeaderNames();
while (headerNames.hasMoreElements()) {
String name = headerNames.nextElement();
String value = req.getHeader(name);
for (IHttpHeaderFilter filter : getRequestHeaderFilters()) {
value = filter.filter(name, value);
}
if (value != null) {
HttpHeaders headers = httpReq.getHeaders();
headers.set(name, Collections.singletonList(value));
LOG.trace("Wrote request header: {}: {}", name, value);
} else {
LOG.trace("Removed request header: {} (original value: {})", name, req.getHeader(name));
}
}
}
use of com.google.api.client.http.HttpHeaders in project providence by morimekta.
the class SetHeadersInitializer method initialize.
@Override
public void initialize(HttpRequest request) {
request.setConnectTimeout(connect_timeout);
request.setReadTimeout(read_timeout);
// With the interceptor will overwrite headers set by the Http client.
request.setInterceptor(rq -> {
HttpHeaders http = rq.getHeaders();
for (Map.Entry<String, String> entry : headers.entrySet()) {
String value = entry.getValue();
switch(entry.getKey().toLowerCase()) {
case "accept":
http.setAccept(value);
break;
case "accept-encoding":
http.setAcceptEncoding(value);
break;
case "authorization":
http.setAuthorization(value);
break;
case "content-encoding":
http.setContentEncoding(value);
break;
case "content-type":
http.setContentType(value);
break;
case "user-agent":
http.setUserAgent(value);
break;
default:
try {
http.set(entry.getKey(), value);
} catch (Exception e) {
// special method.
throw new IOException("Unable to set header " + entry.getKey() + ": " + e.getMessage(), e);
}
break;
}
}
});
}
use of com.google.api.client.http.HttpHeaders in project beam by apache.
the class GcsUtil method enqueueDelete.
private void enqueueDelete(final GcsPath file, BatchInterface batch) throws IOException {
Storage.Objects.Delete deleteRequest = storageClient.objects().delete(file.getBucket(), file.getObject());
batch.queue(deleteRequest, new JsonBatchCallback<Void>() {
@Override
public void onSuccess(Void obj, HttpHeaders responseHeaders) {
LOG.debug("Successfully deleted {}", file);
}
@Override
public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) throws IOException {
if (e.getCode() == 404) {
LOG.info("Ignoring failed deletion of file {} which already does not exist: {}", file, e);
} else {
throw new IOException(String.format("Error trying to delete %s: %s", file, e));
}
}
});
}
use of com.google.api.client.http.HttpHeaders in project copybara by google.
the class GerritApiTransportImpl method getHttpRequestFactory.
/**
* TODO(malcon): Consolidate GitHub and this one in one class
*/
private HttpRequestFactory getHttpRequestFactory(@Nullable UserPassword userPassword) throws RepoException, ValidationException {
return httpTransport.createRequestFactory(request -> {
request.setConnectTimeout((int) Duration.ofMinutes(1).toMillis());
request.setReadTimeout((int) Duration.ofMinutes(1).toMillis());
HttpHeaders httpHeaders = new HttpHeaders();
if (userPassword != null) {
httpHeaders.setBasicAuthentication(userPassword.getUsername(), userPassword.getPassword_BeCareful());
}
request.setHeaders(httpHeaders);
request.setParser(new JsonObjectParser(JSON_FACTORY));
});
}
use of com.google.api.client.http.HttpHeaders in project copybara by google.
the class GitHubApiTransportImpl method maybeGetLinkHeader.
@SuppressWarnings("unchecked")
@Nullable
private static String maybeGetLinkHeader(HttpResponse response) {
HttpHeaders headers = response.getHeaders();
List<String> link = (List<String>) headers.get("Link");
if (link == null) {
return null;
}
return Iterables.getOnlyElement(link);
}
Aggregations