hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r232345 - in /jakarta/httpclient/trunk/http-common/src/java/org/apache/http: StatusLine.java params/HttpProtocolParams.java protocol/ResponseDate.java protocol/ResponseServer.java
Date Fri, 12 Aug 2005 18:13:43 GMT
Author: olegk
Date: Fri Aug 12 11:13:33 2005
New Revision: 232345

URL: http://svn.apache.org/viewcvs?rev=232345&view=rev
Log:
Added origin server and date response interceptors

Added:
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseDate.java
  (with props)
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseServer.java
  (with props)
Modified:
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/StatusLine.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/params/HttpProtocolParams.java

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/StatusLine.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/StatusLine.java?rev=232345&r1=232344&r2=232345&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/StatusLine.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/StatusLine.java Fri Aug
12 11:13:33 2005
@@ -83,6 +83,11 @@
         this.statusCode = statusCode;
         this.reasonPhrase = reasonPhrase;
     }
+
+    public StatusLine(final HttpVersion httpVersion, int statusCode) {
+        this(httpVersion, statusCode, HttpStatus.getStatusText(statusCode));
+    }
+
     /**
      * Parses the status line returned from the HTTP server.
      *

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/params/HttpProtocolParams.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/params/HttpProtocolParams.java?rev=232345&r1=232344&r2=232345&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/params/HttpProtocolParams.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/params/HttpProtocolParams.java
Fri Aug 12 11:13:33 2005
@@ -78,13 +78,20 @@
     public static final String HTTP_CONTENT_CHARSET = "http.protocol.content-charset"; 
     
     /**
-     * Defines the content of the <tt>User-Agent</tt> header used by  
-     * {@link org.apache.commons.httpclient.HttpMethod HTTP methods}.
+     * Defines the content of the <tt>User-Agent</tt> header.
      * <p>
      * This parameter expects a value of type {@link String}.
      * </p>
      */
     public static final String USER_AGENT = "http.useragent"; 
+
+    /**
+     * Defines the content of the <tt>Server</tt> header.
+     * <p>
+     * This parameter expects a value of type {@link String}.
+     * </p>
+     */
+    public static final String ORIGIN_SERVER = "http.origin-server"; 
 
     /**
      * Defines the maximum number of ignorable lines before we expect

Added: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseDate.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseDate.java?rev=232345&view=auto
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseDate.java
(added)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseDate.java
Fri Aug 12 11:13:33 2005
@@ -0,0 +1,83 @@
+/*
+ * $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.protocol;
+
+import java.io.IOException;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+
+import org.apache.http.Header;
+import org.apache.http.HttpException;
+import org.apache.http.HttpMutableResponse;
+import org.apache.http.HttpResponseInterceptor;
+import org.apache.http.HttpStatus;
+import org.apache.http.util.DateUtils;
+
+/**
+ * <p>
+ * </p>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision$
+ * 
+ * @since 4.0
+ */
+public class ResponseDate implements HttpResponseInterceptor {
+
+    private static final String DATE_DIRECTIVE = "Date";
+    
+    private final DateFormat rfc1123; 
+    
+    public ResponseDate() {
+        super();
+        this.rfc1123 = new SimpleDateFormat(DateUtils.PATTERN_RFC1123, Locale.US);
+        this.rfc1123.setTimeZone(DateUtils.GMT);
+    }
+
+    private String getCurrentDate() {
+        synchronized (this.rfc1123) {
+            return this.rfc1123.format(new Date());
+        }
+    }
+    
+    public void process(final HttpMutableResponse response, final HttpContext context) 
+        throws HttpException, IOException {
+        if (response == null) {
+            throw new IllegalArgumentException("HTTP request may not be null");
+        }
+        int status = response.getStatusLine().getStatusCode();
+        if (status >= HttpStatus.SC_OK) {
+            response.setHeader(new Header(DATE_DIRECTIVE, getCurrentDate(), true)); 
+        }
+    }
+    
+}

Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseDate.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseDate.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseDate.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseServer.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseServer.java?rev=232345&view=auto
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseServer.java
(added)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseServer.java
Fri Aug 12 11:13:33 2005
@@ -0,0 +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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.protocol;
+
+import java.io.IOException;
+
+import org.apache.http.Header;
+import org.apache.http.HttpException;
+import org.apache.http.HttpMutableResponse;
+import org.apache.http.HttpResponseInterceptor;
+import org.apache.http.params.HttpProtocolParams;
+
+/**
+ * <p>
+ * </p>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision$
+ * 
+ * @since 4.0
+ */
+public class ResponseServer implements HttpResponseInterceptor {
+
+    private static final String SERVER_DIRECTIVE = "Server";
+    
+    public ResponseServer() {
+        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 (!response.containsHeader(SERVER_DIRECTIVE)) {
+            String s = (String) response.getParams().getParameter(
+                    HttpProtocolParams.ORIGIN_SERVER);
+            if (s != null) {
+                response.setHeader(new Header(SERVER_DIRECTIVE, s, true)); 
+            }
+        }
+    }
+    
+}

Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseServer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseServer.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/protocol/ResponseServer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message