Index: /home/oleg/src/apache.org/jakarta-httpcomponents/http-core/src/examples/org/apache/http/examples/HttpRequestExecutorDemo.java =================================================================== --- /home/oleg/src/apache.org/jakarta-httpcomponents/http-core/src/examples/org/apache/http/examples/HttpRequestExecutorDemo.java (revision 357063) +++ /home/oleg/src/apache.org/jakarta-httpcomponents/http-core/src/examples/org/apache/http/examples/HttpRequestExecutorDemo.java (working copy) @@ -47,6 +47,7 @@ import org.apache.http.protocol.RequestExpectContinue; import org.apache.http.protocol.RequestTargetHost; import org.apache.http.protocol.RequestUserAgent; +import org.apache.http.protocol.ResponseHeadContent; import org.apache.http.util.EntityUtils; /** @@ -77,6 +78,8 @@ httpexecutor.addRequestInterceptor(new RequestConnControl()); httpexecutor.addRequestInterceptor(new RequestUserAgent()); httpexecutor.addRequestInterceptor(new RequestExpectContinue()); + // Recommended response interceptors + httpexecutor.addResponseInterceptor(new ResponseHeadContent()); HttpHost host = new HttpHost("www.yahoo.com"); HttpClientConnection conn = new DefaultHttpClientConnection(host); Index: /home/oleg/src/apache.org/jakarta-httpcomponents/http-core/src/java/org/apache/http/protocol/ResponseHeadContent.java =================================================================== --- /home/oleg/src/apache.org/jakarta-httpcomponents/http-core/src/java/org/apache/http/protocol/ResponseHeadContent.java (revision 0) +++ /home/oleg/src/apache.org/jakarta-httpcomponents/http-core/src/java/org/apache/http/protocol/ResponseHeadContent.java (revision 0) @@ -1 +1,71 @@ +/* + * $HeadURL: $ + * $Revision: $ + * $Date: $ + * + * ==================================================================== + * + * Copyright 1999-2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + +package org.apache.http.protocol; + +import java.io.IOException; + +import org.apache.http.HttpException; +import org.apache.http.HttpMutableResponse; +import org.apache.http.HttpRequest; +import org.apache.http.HttpResponseInterceptor; + +/** + *

+ *

+ * @author Oleg Kalnichevski + * + * @version $Revision: $ + * + * @since 4.0 + */ +public class ResponseHeadContent implements HttpResponseInterceptor { + + private static final String HEAD_METHOD = "HEAD"; + + public ResponseHeadContent() { + super(); + } + + public void process(final HttpMutableResponse response, final HttpContext context) + throws HttpException, IOException { + if (response == null) { + throw new IllegalArgumentException("HTTP request may not be null"); + } + if (context == null) { + throw new IllegalArgumentException("HTTP context may not be null"); + } + HttpRequest request = (HttpRequest) context.getAttribute(HttpContext.HTTP_REQUEST); + + if (HEAD_METHOD.equalsIgnoreCase(request.getRequestLine().getMethod())) { + response.setEntity(null); + } + } + +}