hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r440091 - /jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/
Date Mon, 04 Sep 2006 14:27:44 GMT
Author: olegk
Date: Mon Sep  4 07:27:43 2006
New Revision: 440091

URL: http://svn.apache.org/viewvc?view=rev&rev=440091
Log:
[HTTPCORE-11] Refactored DefaultHttpClientConnection and DefaultHttpServerConnection; removed
AbstractHttpConnection class

Removed:
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpConnection.java
Modified:
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpClientConnection.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultHttpClientConnection.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultHttpServerConnection.java

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpClientConnection.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpClientConnection.java?view=diff&rev=440091&r1=440090&r2=440091
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpClientConnection.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpClientConnection.java
Mon Sep  4 07:27:43 2006
@@ -158,10 +158,15 @@
                 request.getEntity());
     }
 
-    public void flush() throws IOException {
+    protected void doFlush() throws IOException {
         this.datatransmitter.flush();
     }
     
+    public void flush() throws IOException {
+        assertOpen();
+        doFlush();
+    }
+    
     protected void sendRequestLine(final HttpRequest request) 
             throws HttpException, IOException {
         this.buffer.clear();
@@ -213,7 +218,7 @@
      * @return <tt>true</tt> if the line starts with 'HTTP' 
      *   signature, <tt>false</tt> otherwise.
      */
-    private static boolean startsWithHTTP(final CharArrayBuffer buffer) {
+    protected static boolean startsWithHTTP(final CharArrayBuffer buffer) {
         try {
             int i = 0;
             while (HTTP.isWhitespace(buffer.charAt(i))) {
@@ -263,6 +268,16 @@
             throws HttpException, IOException {
         Header[] headers = HeaderUtils.parseHeaders(this.datareceiver, this.maxHeaderCount);
         response.setHeaders(headers);
+    }
+
+    public boolean isStale() {
+        assertOpen();
+        try {
+            this.datareceiver.isDataAvailable(1);
+            return false;
+        } catch (IOException ex) {
+            return true;
+        }
     }
 
 }

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java?view=diff&rev=440091&r1=440090&r2=440091
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java
Mon Sep  4 07:27:43 2006
@@ -219,4 +219,14 @@
         this.datatransmitter.writeLine(this.buffer);
     }
         
+    public boolean isStale() {
+        assertOpen();
+        try {
+            this.datareceiver.isDataAvailable(1);
+            return false;
+        } catch (IOException ex) {
+            return true;
+        }
+    }
+    
 }

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultHttpClientConnection.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultHttpClientConnection.java?view=diff&rev=440091&r1=440090&r2=440091
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultHttpClientConnection.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultHttpClientConnection.java
Mon Sep  4 07:27:43 2006
@@ -32,35 +32,17 @@
 import java.io.IOException;
 import java.net.InetAddress;
 import java.net.Socket;
-import java.util.Iterator;
 
-import org.apache.http.Header;
-import org.apache.http.HttpClientConnection;
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpEntityEnclosingRequest;
-import org.apache.http.HttpException;
 import org.apache.http.HttpHost;
-import org.apache.http.HttpRequest;
-import org.apache.http.HttpResponse;
-import org.apache.http.HttpResponseFactory;
-import org.apache.http.NoHttpResponseException;
-import org.apache.http.ProtocolException;
-import org.apache.http.StatusLine;
-import org.apache.http.entity.EntityDeserializer;
-import org.apache.http.entity.EntitySerializer;
-import org.apache.http.impl.entity.DefaultEntitySerializer;
 import org.apache.http.impl.entity.DefaultEntityDeserializer;
-import org.apache.http.io.CharArrayBuffer;
+import org.apache.http.impl.entity.DefaultEntitySerializer;
+import org.apache.http.impl.io.SocketHttpDataReceiver;
+import org.apache.http.impl.io.SocketHttpDataTransmitter;
+import org.apache.http.io.HttpDataReceiver;
+import org.apache.http.io.HttpDataTransmitter;
 import org.apache.http.io.SocketFactory;
-import org.apache.http.message.BasicHeader;
-import org.apache.http.message.BasicRequestLine;
-import org.apache.http.message.BasicStatusLine;
-import org.apache.http.message.BufferedHeader;
 import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
-import org.apache.http.params.HttpProtocolParams;
-import org.apache.http.protocol.HTTP;
-import org.apache.http.util.HeaderUtils;
 
 /**
  * Default implementation of a client-side HTTP connection.
@@ -71,30 +53,18 @@
  * 
  * @since 4.0
  */
-public class DefaultHttpClientConnection 
-        extends AbstractHttpConnection implements HttpClientConnection {
+public class DefaultHttpClientConnection extends AbstractHttpClientConnection {
 
     private HttpHost targethost = null;
     private InetAddress localAddress = null;
-    private int maxHeaderCount = -1;
 
-    private final CharArrayBuffer buffer; 
-    
-    /*
-     * Dependent interfaces
-     */
-    private HttpResponseFactory responsefactory = null;
-    private EntitySerializer entityserializer = null;
-    private EntityDeserializer entitydeserializer = null;
+    protected volatile boolean open;
+    protected Socket socket = null;
     
     public DefaultHttpClientConnection(final HttpHost targethost, final InetAddress localAddress)
{
         super();
         this.targethost = targethost;
         this.localAddress = localAddress;
-        this.buffer = new CharArrayBuffer(128);
-        this.responsefactory = new DefaultHttpResponseFactory();
-        this.entityserializer = new DefaultEntitySerializer();
-        this.entitydeserializer = new DefaultEntityDeserializer();
     }
     
     public DefaultHttpClientConnection(final HttpHost targethost) {
@@ -105,25 +75,16 @@
         this(null, null);
     }
     
-    public void setResponseFactory(final HttpResponseFactory responsefactory) {
-        if (responsefactory == null) {
-            throw new IllegalArgumentException("Factory may not be null");
-        }
-        this.responsefactory = responsefactory;
-    }
-
-    public void setEntityDeserializer(final EntityDeserializer entitydeserializer) {
-        if (entitydeserializer == null) {
-            throw new IllegalArgumentException("Entity deserializer may not be null");
+    protected void assertNotOpen() {
+        if (this.open) {
+            throw new IllegalStateException("Connection is already open");
         }
-        this.entitydeserializer = entitydeserializer;
     }
-
-    public void setEntitySerializer(final EntitySerializer entityserializer) {
-        if (entityserializer == null) {
-            throw new IllegalArgumentException("Entity serializer may not be null");
+    
+    protected void assertOpen() {
+        if (!this.open) {
+            throw new IllegalStateException("Connection is not open");
         }
-        this.entityserializer = entityserializer;
     }
 
     public void open(final HttpParams params) throws IOException {
@@ -140,9 +101,42 @@
                 this.localAddress, 0, 
                 params);
         bind(socket, params);
-        this.maxHeaderCount = params.getIntParameter(HttpConnectionParams.MAX_HEADER_COUNT,
-1);
     }
     
+    protected void bind(final Socket socket, final HttpParams params) throws IOException
{
+        if (socket == null) {
+            throw new IllegalArgumentException("Socket may not be null");
+        }
+        if (params == null) {
+            throw new IllegalArgumentException("HTTP parameters may not be null");
+        }
+        assertNotOpen();
+        
+        socket.setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(params));
+        socket.setSoTimeout(HttpConnectionParams.getSoTimeout(params));
+        
+        int linger = HttpConnectionParams.getLinger(params);
+        if (linger >= 0) {
+            socket.setSoLinger(linger > 0, linger);
+        }
+
+        this.socket = socket;
+        
+        int buffersize = HttpConnectionParams.getSocketBufferSize(params);
+        HttpDataTransmitter transmitter = new SocketHttpDataTransmitter(socket, buffersize);
+        HttpDataReceiver receiver = new SocketHttpDataReceiver(socket, buffersize);
+        transmitter.reset(params);
+        receiver.reset(params);
+        
+        setHttpDataReceiver(receiver);
+        setHttpDataTransmitter(transmitter);
+        setMaxHeaderCount(params.getIntParameter(HttpConnectionParams.MAX_HEADER_COUNT, -1));
+        setResponseFactory(new DefaultHttpResponseFactory());
+        setEntitySerializer(new DefaultEntitySerializer());
+        setEntityDeserializer(new DefaultEntityDeserializer());
+        this.open = true;
+    }
+
     public HttpHost getTargetHost() {
         return this.targethost;
     }
@@ -164,142 +158,33 @@
         this.localAddress = localAddress;
     }
     
-    public boolean isResponseAvailable(int timeout) throws IOException {
-        assertOpen();
-        return this.datareceiver.isDataAvailable(timeout);
+    public boolean isOpen() {
+        return this.open;
     }
 
-    public void sendRequestHeader(final HttpRequest request) 
-            throws HttpException, IOException {
-        if (request == null) {
-            throw new IllegalArgumentException("HTTP request may not be null");
-        }
-        assertOpen();
-        sendRequestLine(request);
-        sendRequestHeaders(request);
-    }
-
-    public void sendRequestEntity(final HttpEntityEnclosingRequest request) 
-            throws HttpException, IOException {
-        if (request == null) {
-            throw new IllegalArgumentException("HTTP request may not be null");
-        }
-        assertOpen();
-        if (request.getEntity() == null) {
-            return;
+    public void shutdown() throws IOException {
+        this.open = false;
+        Socket tmpsocket = this.socket;
+        if (tmpsocket != null) {
+            tmpsocket.close();
         }
-        this.entityserializer.serialize(
-                this.datatransmitter,
-                request,
-                request.getEntity());
-    }
-
-    public void flush() throws IOException {
-        this.datatransmitter.flush();
     }
     
-    protected void sendRequestLine(final HttpRequest request) 
-            throws HttpException, IOException {
-        this.buffer.clear();
-        BasicRequestLine.format(this.buffer, request.getRequestLine());
-        this.datatransmitter.writeLine(this.buffer);
-    }
-
-    protected void sendRequestHeaders(final HttpRequest request) 
-            throws HttpException, IOException {
-        for (Iterator it = request.headerIterator(); it.hasNext(); ) {
-            Header header = (Header) it.next();
-            if (header instanceof BufferedHeader) {
-                // If the header is backed by a buffer, re-use the buffer
-                this.datatransmitter.writeLine(((BufferedHeader)header).getBuffer());
-            } else {
-                this.buffer.clear();
-                BasicHeader.format(this.buffer, header);
-                this.datatransmitter.writeLine(this.buffer);
-            }
+    public void close() throws IOException {
+        if (!this.open) {
+            return;
         }
-        this.buffer.clear();
-        this.datatransmitter.writeLine(this.buffer);
-    }
-
-    public HttpResponse receiveResponseHeader(final HttpParams params) 
-            throws HttpException, IOException {
-        if (params == null) {
-            throw new IllegalArgumentException("HTTP parameters may not be null");
+        this.open = false;
+        doFlush();
+        try {
+            this.socket.shutdownOutput();
+        } catch (IOException ignore) {
         }
-        assertOpen();
-        HttpResponse response = readResponseStatusLine(params);
-        readResponseHeaders(response);
-        return response;
-    }
-
-    public void receiveResponseEntity(final HttpResponse response)
-            throws HttpException, IOException {
-        if (response == null) {
-            throw new IllegalArgumentException("HTTP response may not be null");
-        }
-        assertOpen();
-        HttpEntity entity = this.entitydeserializer.deserialize(this.datareceiver, response);
-        response.setEntity(entity);
-    }
-    
-    /**
-     * Tests if the string starts with 'HTTP' signature.
-     * @param buffer buffer to test
-     * @return <tt>true</tt> if the line starts with 'HTTP' 
-     *   signature, <tt>false</tt> otherwise.
-     */
-    private static boolean startsWithHTTP(final CharArrayBuffer buffer) {
         try {
-            int i = 0;
-            while (HTTP.isWhitespace(buffer.charAt(i))) {
-                ++i;
-            }
-            return buffer.charAt(i) == 'H' 
-                && buffer.charAt(i + 1) == 'T'
-                && buffer.charAt(i + 2) == 'T'
-                && buffer.charAt(i + 3) == 'P';
-        } catch (IndexOutOfBoundsException e) {
-            return false;
+            this.socket.shutdownInput();
+        } catch (IOException ignore) {
         }
-    }
-    
-    protected HttpResponse readResponseStatusLine(final HttpParams params) 
-                throws HttpException, IOException {
-        // clear the buffer
-        this.buffer.clear();
-        //read out the HTTP status string
-        int maxGarbageLines = params.getIntParameter(
-                HttpProtocolParams.STATUS_LINE_GARBAGE_LIMIT, Integer.MAX_VALUE);
-        int count = 0;
-        do {
-            int i = this.datareceiver.readLine(this.buffer);
-            if (i == -1 && count == 0) {
-                // The server just dropped connection on us
-                throw new NoHttpResponseException("The server " + 
-                        this.targethost.getHostName() + " failed to respond");
-            }
-            if (startsWithHTTP(this.buffer)) {
-                // Got one
-                break;
-            } else if (i == -1 || count >= maxGarbageLines) {
-                // Giving up
-                throw new ProtocolException("The server " + this.targethost.getHostName()
+ 
-                        " failed to respond with a valid HTTP response");
-            }
-            count++;
-        } while(true);
-        //create the status line from the status string
-        StatusLine statusline = BasicStatusLine.parse(this.buffer, 0, this.buffer.length());
-        HttpResponse response = this.responsefactory.newHttpResponse(statusline);
-        response.getParams().setDefaults(params);
-        return response;
-    }
-
-    protected void readResponseHeaders(final HttpResponse response) 
-            throws HttpException, IOException {
-        Header[] headers = HeaderUtils.parseHeaders(this.datareceiver, this.maxHeaderCount);
-        response.setHeaders(headers);
+        this.socket.close();
     }
     
 }

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultHttpServerConnection.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultHttpServerConnection.java?view=diff&rev=440091&r1=440090&r2=440091
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultHttpServerConnection.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultHttpServerConnection.java
Mon Sep  4 07:27:43 2006
@@ -31,33 +31,19 @@
 
 import java.io.IOException;
 import java.net.Socket;
-import java.util.Iterator;
 
-import org.apache.http.ConnectionClosedException;
-import org.apache.http.Header;
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpEntityEnclosingRequest;
-import org.apache.http.HttpException;
-import org.apache.http.HttpRequest;
-import org.apache.http.HttpRequestFactory;
-import org.apache.http.HttpResponse;
-import org.apache.http.HttpServerConnection;
-import org.apache.http.RequestLine;
-import org.apache.http.entity.EntityDeserializer;
-import org.apache.http.entity.EntitySerializer;
 import org.apache.http.impl.entity.DefaultEntityDeserializer;
 import org.apache.http.impl.entity.DefaultEntitySerializer;
-import org.apache.http.io.CharArrayBuffer;
-import org.apache.http.message.BasicHeader;
-import org.apache.http.message.BasicRequestLine;
-import org.apache.http.message.BasicStatusLine;
-import org.apache.http.message.BufferedHeader;
+import org.apache.http.impl.io.SocketHttpDataReceiver;
+import org.apache.http.impl.io.SocketHttpDataTransmitter;
+import org.apache.http.io.HttpDataReceiver;
+import org.apache.http.io.HttpDataTransmitter;
 import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
-import org.apache.http.util.HeaderUtils;
 
 /**
- * Default implementation of a server-side HTTP connection.
+ * Default implementation of a server-side HTTP connection that be bound to a 
+ * network Socket in order to receive and transmit data.
  *
  * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
  *
@@ -65,142 +51,88 @@
  * 
  * @since 4.0
  */
-public class DefaultHttpServerConnection 
-        extends AbstractHttpConnection implements HttpServerConnection {
+public class DefaultHttpServerConnection extends AbstractHttpServerConnection {
 
-    private int maxHeaderCount = -1;
+    protected volatile boolean open;
+    protected Socket socket = null;
     
-    private final CharArrayBuffer buffer; 
-    
-    /*
-     * Dependent interfaces
-     */
-    private HttpRequestFactory requestfactory = null; 
-    private EntitySerializer entityserializer = null;
-    private EntityDeserializer entitydeserializer = null;
-
     public DefaultHttpServerConnection() {
         super();
-        this.requestfactory = new DefaultHttpRequestFactory();
-        this.buffer = new CharArrayBuffer(128);
-        this.entityserializer = new DefaultEntitySerializer();
-        this.entitydeserializer = new DefaultEntityDeserializer();
-    }
-    
-    public void setRequestFactory(final HttpRequestFactory requestfactory) {
-        if (requestfactory == null) {
-            throw new IllegalArgumentException("Factory may not be null");
-        }
-        this.requestfactory = requestfactory;
     }
 
-    public void setEntityDeserializer(final EntityDeserializer entitydeserializer) {
-        if (entitydeserializer == null) {
-            throw new IllegalArgumentException("Entity deserializer may not be null");
+    protected void assertNotOpen() {
+        if (this.open) {
+            throw new IllegalStateException("Connection is already open");
         }
-        this.entitydeserializer = entitydeserializer;
     }
-
-    public void setEntitySerializer(final EntitySerializer entityserializer) {
-        if (entityserializer == null) {
-            throw new IllegalArgumentException("Entity serializer may not be null");
+    
+    protected void assertOpen() {
+        if (!this.open) {
+            throw new IllegalStateException("Connection is not open");
         }
-        this.entityserializer = entityserializer;
     }
 
     public void bind(final Socket socket, final HttpParams params) throws IOException {
-        super.bind(socket, params);
-        this.maxHeaderCount = params.getIntParameter(HttpConnectionParams.MAX_HEADER_COUNT,
-1);
-    }
-
-    public HttpRequest receiveRequestHeader(final HttpParams params) 
-            throws HttpException, IOException {
+        if (socket == null) {
+            throw new IllegalArgumentException("Socket may not be null");
+        }
         if (params == null) {
             throw new IllegalArgumentException("HTTP parameters may not be null");
         }
-        assertOpen();
-        HttpRequest request = receiveRequestLine(params);
-        receiveRequestHeaders(request);
-        return request;
-    }
-    
-    public void receiveRequestEntity(final HttpEntityEnclosingRequest request) 
-            throws HttpException, IOException {
-        if (request == null) {
-            throw new IllegalArgumentException("HTTP request may not be null");
-        }
-        assertOpen();
-        HttpEntity entity = this.entitydeserializer.deserialize(this.datareceiver, request);
-        request.setEntity(entity);
-    }
-
-    protected HttpRequest receiveRequestLine(final HttpParams params)
-            throws HttpException, IOException {
-        this.buffer.clear();
-        int i = this.datareceiver.readLine(this.buffer);
-        if (i == -1) {
-            throw new ConnectionClosedException("Client closed connection"); 
-        }
-        RequestLine requestline = BasicRequestLine.parse(this.buffer, 0, this.buffer.length());
-        HttpRequest request = this.requestfactory.newHttpRequest(requestline);
-        request.getParams().setDefaults(params);
-        return request;
-    }
-    
-    protected void receiveRequestHeaders(final HttpRequest request) 
-            throws HttpException, IOException {
-        Header[] headers = HeaderUtils.parseHeaders(this.datareceiver, this.maxHeaderCount);
-        request.setHeaders(headers);
-    }
+        assertNotOpen();
+
+        socket.setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(params));
+        socket.setSoTimeout(HttpConnectionParams.getSoTimeout(params));
+        
+        int linger = HttpConnectionParams.getLinger(params);
+        if (linger >= 0) {
+            socket.setSoLinger(linger > 0, linger);
+        }
 
-    public void flush() throws IOException {
-        assertOpen();
-        this.datatransmitter.flush();
+        this.socket = socket;
+        
+        int buffersize = HttpConnectionParams.getSocketBufferSize(params);
+        HttpDataTransmitter transmitter = new SocketHttpDataTransmitter(socket, buffersize);
+        HttpDataReceiver receiver = new SocketHttpDataReceiver(socket, buffersize);
+        transmitter.reset(params);
+        receiver.reset(params);
+        
+        setHttpDataReceiver(receiver);
+        setHttpDataTransmitter(transmitter);
+        setMaxHeaderCount(params.getIntParameter(HttpConnectionParams.MAX_HEADER_COUNT, -1));
+        setRequestFactory(new DefaultHttpRequestFactory());
+        setEntitySerializer(new DefaultEntitySerializer());
+        setEntityDeserializer(new DefaultEntityDeserializer());
+        this.open = true;
     }
-    
-	public void sendResponseHeader(final HttpResponse response) 
-            throws HttpException, IOException {
-        if (response == null) {
-            throw new IllegalArgumentException("HTTP response may not be null");
-        }
-        assertOpen();
-        sendResponseStatusLine(response);
-        sendResponseHeaders(response);
+
+    public boolean isOpen() {
+        return this.open;
     }
 
-    public void sendResponseEntity(final HttpResponse response) 
-            throws HttpException, IOException {
-        if (response.getEntity() == null) {
-            return;
+    public void shutdown() throws IOException {
+        this.open = false;
+        Socket tmpsocket = this.socket;
+        if (tmpsocket != null) {
+            tmpsocket.close();
         }
-        this.entityserializer.serialize(
-                this.datatransmitter,
-                response,
-                response.getEntity());
     }
     
-    protected void sendResponseStatusLine(final HttpResponse response) 
-            throws HttpException, IOException {
-        this.buffer.clear();
-        BasicStatusLine.format(this.buffer, response.getStatusLine());
-        this.datatransmitter.writeLine(this.buffer);
-    }
-
-    protected void sendResponseHeaders(final HttpResponse response) 
-            throws HttpException, IOException {
-        for (Iterator it = response.headerIterator(); it.hasNext(); ) {
-            Header header = (Header) it.next();
-            if (header instanceof BufferedHeader) {
-                // If the header is backed by a buffer, re-use the buffer
-                this.datatransmitter.writeLine(((BufferedHeader)header).getBuffer());
-            } else {
-                this.buffer.clear();
-                BasicHeader.format(this.buffer, header);
-                this.datatransmitter.writeLine(this.buffer);
-            }
+    public void close() throws IOException {
+        if (!this.open) {
+            return;
         }
-        this.buffer.clear();
-        this.datatransmitter.writeLine(this.buffer);
+        this.open = false;
+        doFlush();
+        try {
+            this.socket.shutdownOutput();
+        } catch (IOException ignore) {
+        }
+        try {
+            this.socket.shutdownInput();
+        } catch (IOException ignore) {
+        }
+        this.socket.close();
     }
-        
+    
 }



Mime
View raw message