Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 45 additions & 41 deletions src/com/androidquery/callback/AbstractAjaxCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -1764,52 +1764,56 @@ private void httpDo(HttpUriRequest hr, String url, AjaxStatus status) throws Cli
HttpHost currentHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
redirect = currentHost.toURI() + currentReq.getURI();

int size = Math.max(32, Math.min(1024 * 64, (int) entity.getContentLength()));

OutputStream os = null;
InputStream is = null;

try{
file = getPreFile();

int size = 0;

if (entity != null) //entity could be NULL if code = 204, for example (which means "no content")
{
size = Math.max(32, Math.min(1024 * 64, (int) entity.getContentLength()));

if(file == null){
os = new PredefinedBAOS(size);
}else{
//file.createNewFile();
tempFile = makeTempFile(file);
os = new BufferedOutputStream(new FileOutputStream(tempFile));
}

is = entity.getContent();

boolean gzip = "gzip".equalsIgnoreCase(getEncoding(entity));

if(gzip){
is = new GZIPInputStream(is);
}
OutputStream os = null;
InputStream is = null;

int contentLength = (int) entity.getContentLength();

//AQUtility.debug("gzip response", entity.getContentEncoding());

copy(is, os, contentLength, tempFile, file);
try{
file = getPreFile();

//os.flush();
if(file == null){
os = new PredefinedBAOS(size);
}else{
//file.createNewFile();
tempFile = makeTempFile(file);
os = new BufferedOutputStream(new FileOutputStream(tempFile));
}

is = entity.getContent();

boolean gzip = "gzip".equalsIgnoreCase(getEncoding(entity));

if(gzip){
is = new GZIPInputStream(is);
}

int contentLength = (int) entity.getContentLength();

//AQUtility.debug("gzip response", entity.getContentEncoding());

copy(is, os, contentLength, tempFile, file);

//os.flush();

if(file == null){
data = ((PredefinedBAOS) os).toByteArray();
}else{
if(!file.exists() || file.length() == 0){
file = null;
}
}

if(file == null){
data = ((PredefinedBAOS) os).toByteArray();
}else{
if(!file.exists() || file.length() == 0){
file = null;
}
}finally{
AQUtility.close(is);
AQUtility.close(os);
}

}finally{
AQUtility.close(is);
AQUtility.close(os);
}

}
}

AQUtility.debug("response", code);
Expand Down