Return-Path: Delivered-To: apmail-jakarta-httpclient-commits-archive@www.apache.org Received: (qmail 80709 invoked from network); 12 Aug 2005 18:13:46 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 12 Aug 2005 18:13:46 -0000 Received: (qmail 54913 invoked by uid 500); 12 Aug 2005 18:13:45 -0000 Mailing-List: contact httpclient-commits-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: httpclient-dev@jakarta.apache.org Delivered-To: mailing list httpclient-commits@jakarta.apache.org Received: (qmail 54900 invoked by uid 500); 12 Aug 2005 18:13:45 -0000 Delivered-To: apmail-jakarta-httpclient-cvs@jakarta.apache.org Received: (qmail 54897 invoked by uid 99); 12 Aug 2005 18:13:45 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Fri, 12 Aug 2005 11:13:45 -0700 Received: (qmail 80706 invoked by uid 65534); 12 Aug 2005 18:13:44 -0000 Message-ID: <20050812181344.80705.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: httpclient-cvs@jakarta.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.3 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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 User-Agent header used by - * {@link org.apache.commons.httpclient.HttpMethod HTTP methods}. + * Defines the content of the User-Agent header. *

* This parameter expects a value of type {@link String}. *

*/ public static final String USER_AGENT = "http.useragent"; + + /** + * Defines the content of the Server header. + *

+ * This parameter expects a value of type {@link String}. + *

+ */ + 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 + * . + * + */ + +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; + +/** + *

+ *

+ * @author Oleg Kalnichevski + * + * @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 + * . + * + */ + +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; + +/** + *

+ *

+ * @author Oleg Kalnichevski + * + * @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