hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r357788 - in /jakarta/httpcomponents/trunk/http-core/src: contrib/org/apache/http/contrib/benchmark/ java/org/apache/http/impl/ java/org/apache/http/message/
Date Mon, 19 Dec 2005 20:41:21 GMT
Author: olegk
Date: Mon Dec 19 12:41:00 2005
New Revision: 357788

URL: http://svn.apache.org/viewcvs?rev=357788&view=rev
Log:
Added HEAD method

Added:
    jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/message/HttpHead.java
  (with props)
Modified:
    jakarta/httpcomponents/trunk/http-core/src/contrib/org/apache/http/contrib/benchmark/BenchmarkWorker.java
    jakarta/httpcomponents/trunk/http-core/src/contrib/org/apache/http/contrib/benchmark/HttpBenchmark.java
    jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/impl/DefaultHttpRequestFactory.java

Modified: jakarta/httpcomponents/trunk/http-core/src/contrib/org/apache/http/contrib/benchmark/BenchmarkWorker.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/contrib/org/apache/http/contrib/benchmark/BenchmarkWorker.java?rev=357788&r1=357787&r2=357788&view=diff
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/contrib/org/apache/http/contrib/benchmark/BenchmarkWorker.java
(original)
+++ jakarta/httpcomponents/trunk/http-core/src/contrib/org/apache/http/contrib/benchmark/BenchmarkWorker.java
Mon Dec 19 12:41:00 2005
@@ -1,7 +1,7 @@
 /*
- * $HeadURL: $
- * $Revision: $
- * $Date: $
+ * $HeadURL$
+ * $Revision$
+ * $Date$
  *
  * ====================================================================
  *
@@ -33,6 +33,7 @@
 
 import org.apache.http.Header;
 import org.apache.http.HttpClientConnection;
+import org.apache.http.HttpEntity;
 import org.apache.http.HttpException;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
@@ -43,7 +44,7 @@
  * </p>
  * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
  *
- * @version $Revision: $
+ * @version $Revision$
  * 
  * @since 4.0
  */
@@ -68,6 +69,7 @@
         stats.start();
         for (int i = 0; i < count; i++) {
             try {
+                response = this.httpexecutor.execute(request, conn);
                 if (this.verbosity >= 4) {
                     System.out.println(">> " + request.getRequestLine().toString());
                     Header[] headers = request.getAllHeaders();
@@ -76,7 +78,6 @@
                     }
                     System.out.println();
                 }
-                response = this.httpexecutor.execute(request, conn);
                 if (this.verbosity >= 3) {
                     System.out.println(response.getStatusLine().getStatusCode());
                 }
@@ -88,13 +89,16 @@
                     }
                     System.out.println();
                 }
-                InputStream instream = response.getEntity().getContent();
-                byte[] buffer = new byte[4096];
+                HttpEntity entity = response.getEntity();
                 long contentlen = 0;
-                int l = 0;
-                while ((l = instream.read(buffer)) != -1) {
-                    stats.incTotal(l);
-                    contentlen += l;
+                if (entity != null) {
+                    InputStream instream = entity.getContent();
+                    byte[] buffer = new byte[4096];
+                    int l = 0;
+                    while ((l = instream.read(buffer)) != -1) {
+                        stats.incTotal(l);
+                        contentlen += l;
+                    }
                 }
                 if (!keepalive) {
                     conn.close();

Modified: jakarta/httpcomponents/trunk/http-core/src/contrib/org/apache/http/contrib/benchmark/HttpBenchmark.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/contrib/org/apache/http/contrib/benchmark/HttpBenchmark.java?rev=357788&r1=357787&r2=357788&view=diff
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/contrib/org/apache/http/contrib/benchmark/HttpBenchmark.java
(original)
+++ jakarta/httpcomponents/trunk/http-core/src/contrib/org/apache/http/contrib/benchmark/HttpBenchmark.java
Mon Dec 19 12:41:00 2005
@@ -1,7 +1,7 @@
 /*
- * $HeadURL: $
- * $Revision: $
- * $Date: $
+ * $HeadURL$
+ * $Revision$
+ * $Date$
  *
  * ====================================================================
  *
@@ -48,6 +48,7 @@
 import org.apache.http.impl.io.PlainSocketFactory;
 import org.apache.http.impl.io.SSLSocketFactory;
 import org.apache.http.message.HttpGet;
+import org.apache.http.message.HttpHead;
 import org.apache.http.message.HttpPost;
 import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
@@ -63,7 +64,7 @@
  * </p>
  * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
  *
- * @version $Revision: $
+ * @version $Revision$
  * 
  * @since 4.0
  */
@@ -91,6 +92,9 @@
     
     public static void main(String[] args) throws Exception {
 
+        Option iopt = new Option("i", false, "Do HEAD requests instead of GET.");
+        iopt.setRequired(false);
+        
         Option kopt = new Option("k", false, "Enable the HTTP KeepAlive feature, " +
                 "i.e., perform multiple requests within one HTTP session. " +
                 "Default is no KeepAlive");
@@ -121,6 +125,7 @@
         nopt.setRequired(false);
         
         Options options = new Options();
+        options.addOption(iopt);
         options.addOption(kopt);
         options.addOption(nopt);
         options.addOption(popt);
@@ -210,6 +215,9 @@
             HttpPost httppost = new HttpPost(url.getPath());
             httppost.setEntity(entity);
             request = httppost;
+        } else if (cmd.hasOption('i')) {
+            HttpHead httphead = new HttpHead(url.getPath());
+            request = httphead;
         } else {
             HttpGet httpget = new HttpGet(url.getPath());
             request = httpget;

Modified: jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/impl/DefaultHttpRequestFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/impl/DefaultHttpRequestFactory.java?rev=357788&r1=357787&r2=357788&view=diff
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/impl/DefaultHttpRequestFactory.java
(original)
+++ jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/impl/DefaultHttpRequestFactory.java
Mon Dec 19 12:41:00 2005
@@ -59,6 +59,8 @@
         String method = requestline.getMethod();
         if ("GET".equalsIgnoreCase(method)) {
             return new BasicHttpRequest(requestline); 
+        } else if ("HEAD".equalsIgnoreCase(method)) {
+            return new BasicHttpRequest(requestline); 
         } else if ("POST".equalsIgnoreCase(method)) {
             return new BasicHttpEntityEnclosingRequest(requestline); 
         } else { 

Added: jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/message/HttpHead.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/message/HttpHead.java?rev=357788&view=auto
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/message/HttpHead.java
(added)
+++ jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/message/HttpHead.java
Mon Dec 19 12:41:00 2005
@@ -0,0 +1,49 @@
+/*
+ * $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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.message;
+
+/**
+ * <p>
+ * </p>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision$
+ * 
+ * @since 4.0
+ */
+public class HttpHead extends BasicHttpRequest {
+
+    public static String METHOD_NAME = "HEAD";
+    
+    public HttpHead(final String uri) {
+        super(METHOD_NAME, uri);
+    }
+    
+}

Propchange: jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/message/HttpHead.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/message/HttpHead.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/message/HttpHead.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message