fixed a bug in HTTPClient: keep-alive must be set to false, otherwise servers hold connections 2 seconds open until response.

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7151 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 14 years ago
parent 5870b13f3a
commit 5702419194

@ -821,14 +821,14 @@ public final class HTTPDemon implements serverHandler, Cloneable {
// parse data in memory // parse data in memory
FileUpload upload = new FileUpload(diskFileItemFactory); FileUpload upload = new FileUpload(diskFileItemFactory);
List<FileItem> items; List<FileItem> items;
long time = System.currentTimeMillis(); //long time = System.currentTimeMillis();
try { try {
items = upload.parseRequest(request); items = upload.parseRequest(request);
} catch (FileUploadException e) { } catch (FileUploadException e) {
//Log.logException(e); //Log.logException(e);
throw new IOException("FileUploadException " + e.getMessage()); throw new IOException("FileUploadException " + e.getMessage());
} }
System.out.println("**** FileUploadBase.parseRequest time = " + (System.currentTimeMillis() - time)); //System.out.println("**** FileUploadBase.parseRequest time = " + (System.currentTimeMillis() - time));
// format information for further usage // format information for further usage
final HashMap<String, byte[]> files = new HashMap<String, byte[]>(); final HashMap<String, byte[]> files = new HashMap<String, byte[]>();

@ -46,6 +46,7 @@ import net.yacy.cora.protocol.ConnectionInfo;
import org.apache.http.Header; import org.apache.http.Header;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpHost; import org.apache.http.HttpHost;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion; import org.apache.http.HttpVersion;
@ -141,7 +142,7 @@ public class HTTPClient {
HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
// UserAgent // UserAgent
HttpProtocolParams.setUserAgent(httpParams, "yacy (" + systemOST +") yacy.net"); HttpProtocolParams.setUserAgent(httpParams, "yacy (" + systemOST +") yacy.net");
HttpProtocolParams.setUseExpectContinue(httpParams, true); HttpProtocolParams.setUseExpectContinue(httpParams, false); // IMPORTANT - if not set to 'false' then servers do not process the request until a time-out of 2 seconds
/** /**
* HTTP connection settings * HTTP connection settings
*/ */
@ -473,9 +474,18 @@ public class HTTPClient {
// statistics // statistics
storeConnectionInfo(httpUriRequest); storeConnectionInfo(httpUriRequest);
try { try {
// execute the method // execute the method; some asserts confirm that that the request can be send with Content-Length and is therefore not terminated by EOF
if (httpUriRequest instanceof HttpEntityEnclosingRequest) {
HttpEntityEnclosingRequest hrequest = (HttpEntityEnclosingRequest) httpUriRequest;
HttpEntity entity = hrequest.getEntity();
assert entity != null;
assert !entity.isChunked();
assert entity.getContentLength() >= 0;
assert !hrequest.expectContinue();
}
httpResponse = httpClient.execute(httpUriRequest, httpContext); httpResponse = httpClient.execute(httpUriRequest, httpContext);
} catch (Exception e) { } catch (Exception e) {
//e.printStackTrace();
ConnectionInfo.removeConnection(httpUriRequest.hashCode()); ConnectionInfo.removeConnection(httpUriRequest.hashCode());
httpUriRequest.abort(); httpUriRequest.abort();
throw new IOException("Client can't execute: " + e.getMessage()); throw new IOException("Client can't execute: " + e.getMessage());

@ -290,7 +290,6 @@ public final class yacy {
// set user-agent // set user-agent
final String userAgent = "yacy/" + Double.toString(version) + " (www.yacy.net; " final String userAgent = "yacy/" + Double.toString(version) + " (www.yacy.net; "
+ HTTPClient.getSystemOST() + ")"; + HTTPClient.getSystemOST() + ")";
// Client.setUserAgent(userAgent);
HTTPClient.setDefaultUserAgent(userAgent); HTTPClient.setDefaultUserAgent(userAgent);
// start main threads // start main threads

Loading…
Cancel
Save