use of com.amazonaws.services.s3.Headers in project scribejava by scribejava.
the class OkHttpHttpClient method convertResponse.
static Response convertResponse(okhttp3.Response okHttpResponse) {
final Headers headers = okHttpResponse.headers();
final Map<String, String> headersMap = new HashMap<>();
for (String headerName : headers.names()) {
headersMap.put(headerName, headers.get(headerName));
}
final ResponseBody body = okHttpResponse.body();
return new Response(okHttpResponse.code(), okHttpResponse.message(), headersMap, body == null ? null : body.byteStream());
}
use of com.amazonaws.services.s3.Headers in project apollo by spotify.
the class HttpClient method send.
@Override
public CompletionStage<com.spotify.apollo.Response<ByteString>> send(com.spotify.apollo.Request apolloRequest, Optional<com.spotify.apollo.Request> apolloIncomingRequest) {
final Optional<RequestBody> requestBody = apolloRequest.payload().map(payload -> {
final MediaType contentType = apolloRequest.header("Content-Type").map(MediaType::parse).orElse(DEFAULT_CONTENT_TYPE);
return RequestBody.create(contentType, payload);
});
final Headers.Builder headersBuilder = new Headers.Builder();
apolloRequest.headers().asMap().forEach(headersBuilder::add);
apolloIncomingRequest.flatMap(req -> req.header(AUTHORIZATION_HEADER)).ifPresent(header -> {
if (headersBuilder.get(AUTHORIZATION_HEADER) == null) {
headersBuilder.add(AUTHORIZATION_HEADER, header);
}
});
final Request request = new Request.Builder().method(apolloRequest.method(), requestBody.orElse(null)).url(apolloRequest.uri()).headers(headersBuilder.build()).build();
final CompletableFuture<com.spotify.apollo.Response<ByteString>> result = new CompletableFuture<>();
// https://github.com/square/okhttp/wiki/Recipes#per-call-configuration
final OkHttpClient finalClient;
if (apolloRequest.ttl().isPresent() && client.readTimeoutMillis() != apolloRequest.ttl().get().toMillis()) {
finalClient = client.newBuilder().readTimeout(apolloRequest.ttl().get().toMillis(), TimeUnit.MILLISECONDS).build();
} else {
finalClient = client;
}
finalClient.newCall(request).enqueue(TransformingCallback.create(result));
return result;
}
use of com.amazonaws.services.s3.Headers in project incubator-skywalking by apache.
the class RealCallInterceptor method beforeMethod.
/**
* Get the {@link okhttp3.Request} from {@link EnhancedInstance}, then create {@link AbstractSpan} and set host,
* port, kind, component, url from {@link okhttp3.Request}.
* Through the reflection of the way, set the http header of context data into {@link okhttp3.Request#headers}.
*
* @param method
* @param result change this result, if you want to truncate the method.
* @throws Throwable
*/
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
Request request = (Request) objInst.getSkyWalkingDynamicField();
ContextCarrier contextCarrier = new ContextCarrier();
HttpUrl requestUrl = request.url();
AbstractSpan span = ContextManager.createExitSpan(requestUrl.uri().getPath(), contextCarrier, requestUrl.host() + ":" + requestUrl.port());
span.setComponent(ComponentsDefine.OKHTTP);
Tags.HTTP.METHOD.set(span, request.method());
Tags.URL.set(span, requestUrl.uri().toString());
SpanLayer.asHttp(span);
Field headersField = Request.class.getDeclaredField("headers");
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(headersField, headersField.getModifiers() & ~Modifier.FINAL);
headersField.setAccessible(true);
Headers.Builder headerBuilder = request.headers().newBuilder();
CarrierItem next = contextCarrier.items();
while (next.hasNext()) {
next = next.next();
headerBuilder.add(next.getHeadKey(), next.getHeadValue());
}
headersField.set(request, headerBuilder.build());
}
use of com.amazonaws.services.s3.Headers in project spring-cloud-netflix by spring-cloud.
the class OkHttpStatusCodeExceptionTest method getResponse.
@Test
public void getResponse() throws Exception {
Headers headers = new Headers.Builder().add("foo", "bar").build();
Response response = new Response.Builder().code(200).headers(headers).code(200).message("Success").body(ResponseBody.create(MediaType.parse("text/plain"), "foo")).protocol(Protocol.HTTP_1_1).request(new Request.Builder().url("http://service.com").build()).build();
ResponseBody body = response.peekBody(Integer.MAX_VALUE);
OkHttpStatusCodeException ex = new OkHttpStatusCodeException("service", response, body, new URI("http://service.com"));
assertEquals(headers, ex.getResponse().headers());
assertEquals(200, ex.getResponse().code());
assertEquals("Success", ex.getResponse().message());
assertEquals("foo", ex.getResponse().body().string());
assertEquals(Protocol.HTTP_1_1, ex.getResponse().protocol());
}
use of com.amazonaws.services.s3.Headers in project edx-app-android by edx.
the class NoCacheHeaderStrippingInterceptor method intercept.
@NonNull
@Override
public Response intercept(@NonNull final Chain chain) throws IOException {
final Request request = chain.request();
final Response response = chain.proceed(request);
final Headers headers = response.headers();
Headers.Builder strippedHeadersBuilder = null;
List<String> headersToStrip = null;
for (int i = 0, headersCount = headers.size(); i < headersCount; i++) {
final String headerName = headers.name(i);
final String headerValue = headers.value(i);
if (headerName.equalsIgnoreCase("Cache-Control")) {
Matcher directiveMatcher = PATTERN_NO_CACHE_HEADER.matcher(headerValue);
if (directiveMatcher.find()) {
if (strippedHeadersBuilder == null) {
strippedHeadersBuilder = new Headers.Builder();
for (int j = 0; j < i; j++) {
strippedHeadersBuilder.add(headers.name(j), headers.value(j));
}
headersToStrip = new ArrayList<>();
}
String newHeaderValue = headerValue;
while (true) {
Collections.addAll(headersToStrip, directiveMatcher.group(GROUP_NO_CACHE_HEADERS).trim().split("\\s*,\\s*"));
final StringBuffer newHeaderValueBuffer = new StringBuffer();
directiveMatcher.appendReplacement(newHeaderValueBuffer, "$" + (directiveMatcher.group(GROUP_SEPARATOR_START).isEmpty() ? GROUP_SEPARATOR_END : GROUP_SEPARATOR_START));
directiveMatcher.appendTail(newHeaderValueBuffer);
newHeaderValue = newHeaderValueBuffer.toString();
directiveMatcher = PATTERN_NO_CACHE_HEADER.matcher(newHeaderValue);
if (!directiveMatcher.find())
break;
}
if (!newHeaderValue.isEmpty()) {
strippedHeadersBuilder.add(headerName, newHeaderValue);
}
continue;
}
}
if (strippedHeadersBuilder != null) {
strippedHeadersBuilder.add(headerName, headerValue);
}
}
if (strippedHeadersBuilder == null) {
return response;
}
final HttpUrl url = request.url();
List<Cookie> cookies = null;
for (final String headerToStrip : headersToStrip) {
strippedHeadersBuilder.removeAll(headerToStrip);
if (headerToStrip.equalsIgnoreCase("Set-Cookie")) {
if (cookieJar != CookieJar.NO_COOKIES) {
for (final String cookieString : headers.values(headerToStrip)) {
Cookie cookie = Cookie.parse(url, cookieString);
if (cookie != null) {
if (cookies == null) {
cookies = new ArrayList<>();
}
cookies.add(cookie);
}
}
}
}
}
if (cookies != null) {
cookieJar.saveFromResponse(url, cookies);
}
return response.newBuilder().headers(strippedHeadersBuilder.build()).build();
}
Aggregations