You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2005/04/07 21:52:21 UTC
svn commit: r160445 - in
jakarta/httpclient/trunk/http-common/src/java/org/apache/http:
HttpClientConnection.java HttpEntityEnclosingMessage.java HttpHost.java
HttpOutgoingEntity.java impl/DefaultHttpClientConnection.java
Author: olegk
Date: Thu Apr 7 12:52:19 2005
New Revision: 160445
URL: http://svn.apache.org/viewcvs?view=rev&rev=160445
Log:
* Changed HttpClientConnection interface (implementation of 'expect: 100-continue' handshake required ability to permaturely terminate transmition of HTTP request)
* Initial implementation of the 'expect: 100-continue' on the client side
Modified:
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpClientConnection.java
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpEntityEnclosingMessage.java
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpHost.java
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpOutgoingEntity.java
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpClientConnection.java
Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpClientConnection.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpClientConnection.java?view=diff&r1=160444&r2=160445
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpClientConnection.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpClientConnection.java Thu Apr 7 12:52:19 2005
@@ -47,8 +47,8 @@
void open(HttpHost host, HttpParams params, InetAddress localAddress) throws IOException;
- void sendRequest(HttpRequest request) throws HttpException, IOException;
+ HttpResponse sendRequest(HttpRequest request) throws HttpException, IOException;
- HttpResponse receiveResponse(HttpParams params) throws HttpException, IOException;
+ HttpResponse receiveResponse(HttpRequest request) throws HttpException, IOException;
}
Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpEntityEnclosingMessage.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpEntityEnclosingMessage.java?view=diff&r1=160444&r2=160445
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpEntityEnclosingMessage.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpEntityEnclosingMessage.java Thu Apr 7 12:52:19 2005
@@ -38,10 +38,10 @@
*
* @since 4.0
*/
-public interface HttpEntityEnclosingMessage {
+public interface HttpEntityEnclosingMessage extends HttpMessage {
void setEntity(HttpOutgoingEntity entity);
- void setUseChunkEncoding(boolean b);
+ HttpOutgoingEntity getEntity();
}
Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpHost.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpHost.java?view=diff&r1=160444&r2=160445
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpHost.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpHost.java Thu Apr 7 12:52:19 2005
@@ -147,9 +147,19 @@
* @return The host uri.
*/
public String toURI() {
- StringBuffer buffer = new StringBuffer(50);
+ StringBuffer buffer = new StringBuffer();
buffer.append(this.protocol.getScheme());
buffer.append("://");
+ buffer.append(this.hostname);
+ if (this.port != this.protocol.getDefaultPort()) {
+ buffer.append(':');
+ buffer.append(this.port);
+ }
+ return buffer.toString();
+ }
+
+ public String toHostString() {
+ StringBuffer buffer = new StringBuffer();
buffer.append(this.hostname);
if (this.port != this.protocol.getDefaultPort()) {
buffer.append(':');
Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpOutgoingEntity.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpOutgoingEntity.java?view=diff&r1=160444&r2=160445
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpOutgoingEntity.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpOutgoingEntity.java Thu Apr 7 12:52:19 2005
@@ -30,7 +30,8 @@
package org.apache.http;
import java.io.IOException;
-import java.io.OutputStream;
+
+import org.apache.http.io.HttpDataTransmitter;
/**
* <p>
@@ -43,6 +44,6 @@
*/
public interface HttpOutgoingEntity extends HttpEntity {
- void writeTo(OutputStream outstream) throws IOException;
+ void writeTo(HttpDataTransmitter datatransmitter) throws IOException;
}
Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpClientConnection.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpClientConnection.java?view=diff&r1=160444&r2=160445
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpClientConnection.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpClientConnection.java Thu Apr 7 12:52:19 2005
@@ -41,9 +41,11 @@
import org.apache.http.HttpHost;
import org.apache.http.HttpMutableEntity;
import org.apache.http.HttpMutableResponse;
+import org.apache.http.HttpOutgoingEntity;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
+import org.apache.http.HttpVersion;
import org.apache.http.NoHttpResponseException;
import org.apache.http.ProtocolException;
import org.apache.http.ProtocolSocketFactory;
@@ -64,8 +66,11 @@
public class DefaultHttpClientConnection
extends AbstractHttpConnection implements HttpClientConnection {
+ private static final String EXPECT_DIRECTIVE = "Expect";
+ private static final String EXPECT_CONTINUE = "100-Continue";
+ private static final int CONTINUE_WAIT_MS = 3000;
+
private HttpHost targethost = null;
- private boolean reusable = false;
public DefaultHttpClientConnection() {
super();
@@ -88,7 +93,6 @@
targethost.getHostName(), targethost.getPort(), localAddress, 0, params);
bind(socket, params);
this.targethost = targethost;
- this.reusable = true;
}
public HttpHost getTargetHost() {
@@ -97,11 +101,10 @@
public void close() throws IOException {
this.targethost = null;
- this.reusable = false;
super.close();
}
- public void sendRequest(final HttpRequest request)
+ public HttpResponse sendRequest(final HttpRequest request)
throws HttpException, IOException {
if (request == null) {
throw new IllegalArgumentException("HTTP request may not be null");
@@ -112,10 +115,14 @@
sendRequestLine(request);
sendRequestHeaders(request);
+
+ HttpResponse response = null;
if (request instanceof HttpEntityEnclosingMessage) {
- sendRequestBody((HttpEntityEnclosingMessage)request);
+ // send request may be prematurely terminated by the target server
+ response = sendRequestBody(request);
}
this.datatransmitter.flush();
+ return response;
}
protected void sendRequestLine(
@@ -143,22 +150,50 @@
}
}
- protected void sendRequestBody(
- final HttpEntityEnclosingMessage request) throws HttpException, IOException {
+ protected HttpResponse sendRequestBody(final HttpRequest request)
+ throws HttpException, IOException {
+ HttpOutgoingEntity entity = ((HttpEntityEnclosingMessage)request).getEntity();
+ if (entity == null) {
+ return null;
+ }
+ // See if 'expect-continue' handshake is supported
+ if (HttpVersion.HTTP_1_1.greaterEquals(request.getRequestLine().getHttpVersion())) {
+ // ... and activated
+ Header expect = request.getFirstHeader(EXPECT_DIRECTIVE);
+ if (expect != null && EXPECT_CONTINUE.equalsIgnoreCase(expect.getValue())) {
+ // flush the headers
+ this.datatransmitter.flush();
+ if (this.datareceiver.isDataAvailable(CONTINUE_WAIT_MS)) {
+ HttpResponse response = receiveResponse(request);
+ int status = response.getStatusLine().getStatusCode();
+ if (status > 100) {
+ return response;
+ } else {
+ if (status != HttpStatus.SC_CONTINUE) {
+ throw new ProtocolException("Unexpected response: " +
+ response.getStatusLine());
+ }
+ }
+ }
+ }
+ }
+ entity.writeTo(this.datatransmitter);
+ return null;
}
- public HttpResponse receiveResponse(final HttpParams params)
- throws HttpException, IOException {
- if (params == null) {
- throw new IllegalArgumentException("HTTP parameters may not be null");
+ public HttpResponse receiveResponse(final HttpRequest request)
+ throws HttpException, IOException {
+ if (request == null) {
+ throw new IllegalArgumentException("HTTP request may not be null");
}
assertOpen();
+ HttpParams params = request.getParams();
// reset the data receiver
this.datareceiver.reset(params);
BasicHttpResponse response = new BasicHttpResponse();
- response.setParams(params);
+ response.setParams((HttpParams)params.clone());
processResponseStatusLine(response);
processResponseHeaders(response);