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 2006/11/14 11:45:16 UTC
svn commit: r474722 -
/jakarta/httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpServer.java
Author: olegk
Date: Tue Nov 14 02:45:16 2006
New Revision: 474722
URL: http://svn.apache.org/viewvc?view=rev&rev=474722
Log:
Some minor tweaks to the sample elemental HTTP server
Modified:
jakarta/httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpServer.java
Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpServer.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpServer.java?view=diff&rev=474722&r1=474721&r2=474722
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpServer.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpServer.java Tue Nov 14 02:45:16 2006
@@ -39,6 +39,8 @@
import java.net.URLDecoder;
import org.apache.http.ConnectionClosedException;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
@@ -65,6 +67,7 @@
import org.apache.http.protocol.ResponseContent;
import org.apache.http.protocol.ResponseDate;
import org.apache.http.protocol.ResponseServer;
+import org.apache.http.util.EntityUtils;
/**
* Basic, yet fully functional and spec compliant, HTTP/1.1 file server.
@@ -99,11 +102,17 @@
final HttpResponse response,
final HttpContext context) throws HttpException, IOException {
- String method = request.getRequestLine().getMethod();
- if (!method.equalsIgnoreCase("GET") && !method.equalsIgnoreCase("HEAD")) {
+ String method = request.getRequestLine().getMethod().toUpperCase();
+ if (!method.equals("GET") && !method.equals("HEAD") && !method.equals("POST")) {
throw new MethodNotSupportedException(method + " method not supported");
}
String target = request.getRequestLine().getUri();
+
+ if (request instanceof HttpEntityEnclosingRequest) {
+ HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
+ byte[] entityContent = EntityUtils.toByteArray(entity);
+ System.out.println("Incoming entity content (bytes): " + entityContent.length);
+ }
final File file = new File(this.docRoot, URLDecoder.decode(target));
if (!file.exists()) {