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 2008/01/10 13:26:59 UTC
svn commit: r610772 - in /httpcomponents/httpcore/trunk: RELEASE_NOTES.txt
module-main/src/main/java/org/apache/http/impl/DefaultHttpRequestFactory.java
Author: olegk
Date: Thu Jan 10 04:26:57 2008
New Revision: 610772
URL: http://svn.apache.org/viewvc?rev=610772&view=rev
Log:
HTTPCORE-137: DefaultHttpRequestFactory extended to support all methods specified in RFC 2616 (except CONNECT)
Modified:
httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultHttpRequestFactory.java
Modified: httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt?rev=610772&r1=610771&r2=610772&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpcore/trunk/RELEASE_NOTES.txt Thu Jan 10 04:26:57 2008
@@ -1,5 +1,9 @@
Changes since 4.0 Alpha 6
+* [HTTPCORE-137] DefaultHttpRequestFactory extended to support all methods
+ specified in RFC 2616 (except CONNECT).
+ Contributed by Oleg Kalnichevski <olegk at apache.org>
+
* Replaced HTTP parameter linking with a simple child/parent stack.
Contributed by Oleg Kalnichevski <olegk at apache.org>
Modified: httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultHttpRequestFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultHttpRequestFactory.java?rev=610772&r1=610771&r2=610772&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultHttpRequestFactory.java (original)
+++ httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultHttpRequestFactory.java Thu Jan 10 04:26:57 2008
@@ -49,9 +49,35 @@
*/
public class DefaultHttpRequestFactory implements HttpRequestFactory {
+ private static final String[] RFC2616_COMMON_METHODS = {
+ "GET"
+ };
+
+ private static final String[] RFC2616_ENTITY_ENC_METHODS = {
+ "POST",
+ "PUT"
+ };
+
+ private static final String[] RFC2616_SPECIAL_METHODS = {
+ "HEAD",
+ "OPTIONS",
+ "DELETE",
+ "TRACE"
+ };
+
+
public DefaultHttpRequestFactory() {
super();
}
+
+ private static boolean isOneOf(final String[] methods, final String method) {
+ for (int i = 0; i < methods.length; i++) {
+ if (methods[i].equalsIgnoreCase(method)) {
+ return true;
+ }
+ }
+ return false;
+ }
public HttpRequest newHttpRequest(final RequestLine requestline)
throws MethodNotSupportedException {
@@ -59,12 +85,12 @@
throw new IllegalArgumentException("Request line may not be null");
}
String method = requestline.getMethod();
- if ("GET".equalsIgnoreCase(method)) {
+ if (isOneOf(RFC2616_COMMON_METHODS, method)) {
return new BasicHttpRequest(requestline);
- } else if ("HEAD".equalsIgnoreCase(method)) {
- return new BasicHttpRequest(requestline);
- } else if ("POST".equalsIgnoreCase(method)) {
+ } else if (isOneOf(RFC2616_ENTITY_ENC_METHODS, method)) {
return new BasicHttpEntityEnclosingRequest(requestline);
+ } else if (isOneOf(RFC2616_SPECIAL_METHODS, method)) {
+ return new BasicHttpRequest(requestline);
} else {
throw new MethodNotSupportedException(method + " method not supported");
}
@@ -72,10 +98,12 @@
public HttpRequest newHttpRequest(final String method, final String uri)
throws MethodNotSupportedException {
- if ("GET".equalsIgnoreCase(method)) {
- return new BasicHttpRequest(method, uri);
- } else if ("POST".equalsIgnoreCase(method)) {
- return new BasicHttpEntityEnclosingRequest(method, uri);
+ if (isOneOf(RFC2616_COMMON_METHODS, method)) {
+ return new BasicHttpRequest(method, uri);
+ } else if (isOneOf(RFC2616_ENTITY_ENC_METHODS, method)) {
+ return new BasicHttpEntityEnclosingRequest(method, uri);
+ } else if (isOneOf(RFC2616_SPECIAL_METHODS, method)) {
+ return new BasicHttpRequest(method, uri);
} else {
throw new MethodNotSupportedException(method
+ " method not supported");