From 57024191940fd34c31bde8fed91d615cca35b654 Mon Sep 17 00:00:00 2001 From: orbiter Date: Tue, 14 Sep 2010 22:25:35 +0000 Subject: [PATCH] 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 --- source/de/anomic/http/server/HTTPDemon.java | 4 ++-- source/net/yacy/cora/protocol/http/HTTPClient.java | 14 ++++++++++++-- source/net/yacy/yacy.java | 1 - 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/source/de/anomic/http/server/HTTPDemon.java b/source/de/anomic/http/server/HTTPDemon.java index 751e34271..cf830896c 100644 --- a/source/de/anomic/http/server/HTTPDemon.java +++ b/source/de/anomic/http/server/HTTPDemon.java @@ -821,14 +821,14 @@ public final class HTTPDemon implements serverHandler, Cloneable { // parse data in memory FileUpload upload = new FileUpload(diskFileItemFactory); List items; - long time = System.currentTimeMillis(); + //long time = System.currentTimeMillis(); try { items = upload.parseRequest(request); } catch (FileUploadException e) { //Log.logException(e); 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 final HashMap files = new HashMap(); diff --git a/source/net/yacy/cora/protocol/http/HTTPClient.java b/source/net/yacy/cora/protocol/http/HTTPClient.java index 279c33039..422fab54e 100644 --- a/source/net/yacy/cora/protocol/http/HTTPClient.java +++ b/source/net/yacy/cora/protocol/http/HTTPClient.java @@ -46,6 +46,7 @@ import net.yacy.cora.protocol.ConnectionInfo; import org.apache.http.Header; import org.apache.http.HttpEntity; +import org.apache.http.HttpEntityEnclosingRequest; import org.apache.http.HttpHost; import org.apache.http.HttpResponse; import org.apache.http.HttpVersion; @@ -141,7 +142,7 @@ public class HTTPClient { HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); // UserAgent 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 */ @@ -473,9 +474,18 @@ public class HTTPClient { // statistics storeConnectionInfo(httpUriRequest); 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); } catch (Exception e) { + //e.printStackTrace(); ConnectionInfo.removeConnection(httpUriRequest.hashCode()); httpUriRequest.abort(); throw new IOException("Client can't execute: " + e.getMessage()); diff --git a/source/net/yacy/yacy.java b/source/net/yacy/yacy.java index 135278a75..b178cc59b 100644 --- a/source/net/yacy/yacy.java +++ b/source/net/yacy/yacy.java @@ -290,7 +290,6 @@ public final class yacy { // set user-agent final String userAgent = "yacy/" + Double.toString(version) + " (www.yacy.net; " + HTTPClient.getSystemOST() + ")"; -// Client.setUserAgent(userAgent); HTTPClient.setDefaultUserAgent(userAgent); // start main threads