use of com.amazonaws.services.s3.Headers in project edx-app-android by edx.
the class OnlyIfCachedStrippingInterceptor method intercept.
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
if (request.cacheControl().onlyIfCached()) {
final Headers headers = request.headers();
final Headers.Builder strippedHeadersBuilder = new Headers.Builder();
for (int i = 0, headersCount = headers.size(); i < headersCount; i++) {
final String headerName = headers.name(i);
String headerValue = headers.value(i);
if (headerName.equalsIgnoreCase("Cache-Control")) {
Matcher directiveMatcher = PATTERN_ONLY_IF_CACHED_HEADER.matcher(headerValue);
if (directiveMatcher.find()) {
while (true) {
final StringBuffer newHeaderValueBuffer = new StringBuffer();
directiveMatcher.appendReplacement(newHeaderValueBuffer, "$" + (directiveMatcher.group(GROUP_SEPARATOR_START).isEmpty() ? GROUP_SEPARATOR_END : GROUP_SEPARATOR_START));
directiveMatcher.appendTail(newHeaderValueBuffer);
headerValue = newHeaderValueBuffer.toString();
directiveMatcher = PATTERN_ONLY_IF_CACHED_HEADER.matcher(headerValue);
if (!directiveMatcher.find())
break;
}
if (headerName.isEmpty())
continue;
}
}
strippedHeadersBuilder.add(headerName, headerValue);
}
request = request.newBuilder().headers(strippedHeadersBuilder.build()).build();
}
return chain.proceed(request);
}
use of com.amazonaws.services.s3.Headers in project okhttp-OkGo by jeasonlzy.
the class HttpLoggingInterceptor method logForRequest.
private void logForRequest(Request request, Connection connection) throws IOException {
boolean logBody = (printLevel == Level.BODY);
boolean logHeaders = (printLevel == Level.BODY || printLevel == Level.HEADERS);
RequestBody requestBody = request.body();
boolean hasRequestBody = requestBody != null;
Protocol protocol = connection != null ? connection.protocol() : Protocol.HTTP_1_1;
try {
String requestStartMessage = "--> " + request.method() + ' ' + request.url() + ' ' + protocol;
log(requestStartMessage);
if (logHeaders) {
Headers headers = request.headers();
for (int i = 0, count = headers.size(); i < count; i++) {
log("\t" + headers.name(i) + ": " + headers.value(i));
}
log(" ");
if (logBody && hasRequestBody) {
if (isPlaintext(requestBody.contentType())) {
bodyToString(request);
} else {
log("\tbody: maybe [file part] , too large too print , ignored!");
}
}
}
} catch (Exception e) {
OkLogger.e(e);
} finally {
log("--> END " + request.method());
}
}
use of com.amazonaws.services.s3.Headers in project okhttputils by hongyangAndroid.
the class LoggerInterceptor method logForRequest.
private void logForRequest(Request request) {
try {
String url = request.url().toString();
Headers headers = request.headers();
Log.e(tag, "========request'log=======");
Log.e(tag, "method : " + request.method());
Log.e(tag, "url : " + url);
if (headers != null && headers.size() > 0) {
Log.e(tag, "headers : " + headers.toString());
}
RequestBody requestBody = request.body();
if (requestBody != null) {
MediaType mediaType = requestBody.contentType();
if (mediaType != null) {
Log.e(tag, "requestBody's contentType : " + mediaType.toString());
if (isText(mediaType)) {
Log.e(tag, "requestBody's content : " + bodyToString(request));
} else {
Log.e(tag, "requestBody's content : " + " maybe [file part] , too large too print , ignored!");
}
}
}
Log.e(tag, "========request'log=======end");
} catch (Exception e) {
// e.printStackTrace();
}
}
use of com.amazonaws.services.s3.Headers in project okhttp by square.
the class JavaApiConverterTest method createOkRequest_nullRequestHeaderKey.
// Older versions of OkHttp would store the "request line" as a header with a
// null key. To support the Android usecase where an old version of OkHttp uses
// a newer, Android-bundled, version of HttpResponseCache the null key must be
// explicitly ignored.
@Test
public void createOkRequest_nullRequestHeaderKey() throws Exception {
URI uri = new URI("https://foo/bar");
Map<String, List<String>> javaRequestHeaders = new LinkedHashMap<>();
javaRequestHeaders.put(null, Arrays.asList("GET / HTTP 1.1"));
javaRequestHeaders.put("Foo", Arrays.asList("Bar"));
Request request = JavaApiConverter.createOkRequest(uri, "POST", javaRequestHeaders);
assertTrue(request.isHttps());
assertEquals(uri, request.url().uri());
Headers okRequestHeaders = request.headers();
assertEquals(1, okRequestHeaders.size());
assertEquals("Bar", okRequestHeaders.get("Foo"));
assertEquals("POST", request.method());
}
use of com.amazonaws.services.s3.Headers in project okhttp by square.
the class Main method run.
@Override
public void run() {
if (showHelpIfRequested()) {
return;
}
if (version) {
System.out.println(NAME + " " + versionString());
System.out.println("Protocols: " + protocols());
return;
}
if (showHttp2Frames) {
enableHttp2FrameLogging();
}
client = createClient();
Request request = createRequest();
try {
Response response = client.newCall(request).execute();
if (showHeaders) {
System.out.println(StatusLine.get(response));
Headers headers = response.headers();
for (int i = 0, size = headers.size(); i < size; i++) {
System.out.println(headers.name(i) + ": " + headers.value(i));
}
System.out.println();
}
// Stream the response to the System.out as it is returned from the server.
Sink out = Okio.sink(System.out);
BufferedSource source = response.body().source();
while (!source.exhausted()) {
out.write(source.buffer(), source.buffer().size());
out.flush();
}
response.body().close();
} catch (IOException e) {
e.printStackTrace();
} finally {
close();
}
}
Aggregations