@Override public void onHeaders(Response response) { HttpFields headers = response.getHeaders(); long length = headers.getLongField(HttpHeader.CONTENT_LENGTH.asString()); if (length > maxLength) response.abort(new IllegalArgumentException("Buffering capacity exceeded")); String contentType = headers.get(HttpHeader.CONTENT_TYPE); if (contentType != null) { String charset = "charset="; int index = contentType.toLowerCase(Locale.ENGLISH).indexOf(charset); if (index > 0) { String encoding = contentType.substring(index + charset.length()); // Sometimes charsets arrive with an ending semicolon index = encoding.indexOf(';'); if (index > 0) encoding = encoding.substring(0, index); this.encoding = encoding; } } }
@Override public boolean abort(Throwable cause) { return response.abort(cause); }