[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gzz-commits] storm/org/nongnu/storm http/server/HTTPConnecti...
From: |
Benja Fallenstein |
Subject: |
[Gzz-commits] storm/org/nongnu/storm http/server/HTTPConnecti... |
Date: |
Mon, 26 May 2003 22:22:51 -0400 |
CVSROOT: /cvsroot/storm
Module name: storm
Changes by: Benja Fallenstein <address@hidden> 03/05/26 22:22:50
Modified files:
org/nongnu/storm/http/server: HTTPConnection.java
org/nongnu/storm/util: HTTPProxy.java
Log message:
also rewrite on PUT, make httpkit's server part allow WebDAV requests
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/storm/storm/org/nongnu/storm/http/server/HTTPConnection.java.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/storm/storm/org/nongnu/storm/util/HTTPProxy.java.diff?tr1=1.44&tr2=1.45&r1=text&r2=text
Patches:
Index: storm/org/nongnu/storm/http/server/HTTPConnection.java
diff -u storm/org/nongnu/storm/http/server/HTTPConnection.java:1.3
storm/org/nongnu/storm/http/server/HTTPConnection.java:1.4
--- storm/org/nongnu/storm/http/server/HTTPConnection.java:1.3 Mon May 5
09:57:09 2003
+++ storm/org/nongnu/storm/http/server/HTTPConnection.java Mon May 26
22:22:50 2003
@@ -218,6 +218,99 @@
return doUnknown(req, resf);
}
+ // WebDAV methods
+
+ /** HTTP PROPFIND method handler. This method is called when the
+ * HTTP PROPFIND request is to be processed. By default, doUnknown
+ * is called.
+ * @param req The HTTP request from the client
+ * @param resf A factory of HTTP responses
+ * @return A HTTP response to be sent to the client
+ * @throws IOException
+ */
+ protected HTTPResponse doPropfind(HTTPRequest req, HTTPResponse.Factory
resf)
+ throws IOException {
+ return doUnknown(req, resf);
+ }
+
+ /** HTTP PROPPATCH method handler. This method is called when the
+ * HTTP PROPPATCH request is to be processed. By default, doUnknown
+ * is called.
+ * @param req The HTTP request from the client
+ * @param resf A factory of HTTP responses
+ * @return A HTTP response to be sent to the client
+ * @throws IOException
+ */
+ protected HTTPResponse doProppatch(HTTPRequest req, HTTPResponse.Factory
resf)
+ throws IOException {
+ return doUnknown(req, resf);
+ }
+
+ /** HTTP MKCOL method handler. This method is called when the
+ * HTTP MKCOL request is to be processed. By default, doUnknown
+ * is called.
+ * @param req The HTTP request from the client
+ * @param resf A factory of HTTP responses
+ * @return A HTTP response to be sent to the client
+ * @throws IOException
+ */
+ protected HTTPResponse doMkcol(HTTPRequest req, HTTPResponse.Factory resf)
+ throws IOException {
+ return doUnknown(req, resf);
+ }
+
+ /** HTTP COPY method handler. This method is called when the
+ * HTTP COPY request is to be processed. By default, doUnknown
+ * is called.
+ * @param req The HTTP request from the client
+ * @param resf A factory of HTTP responses
+ * @return A HTTP response to be sent to the client
+ * @throws IOException
+ */
+ protected HTTPResponse doCopy(HTTPRequest req, HTTPResponse.Factory resf)
+ throws IOException {
+ return doUnknown(req, resf);
+ }
+
+ /** HTTP MOVE method handler. This method is called when the
+ * HTTP MOVE request is to be processed. By default, doUnknown
+ * is called.
+ * @param req The HTTP request from the client
+ * @param resf A factory of HTTP responses
+ * @return A HTTP response to be sent to the client
+ * @throws IOException
+ */
+ protected HTTPResponse doMove(HTTPRequest req, HTTPResponse.Factory resf)
+ throws IOException {
+ return doUnknown(req, resf);
+ }
+
+ /** HTTP LOCK method handler. This method is called when the
+ * HTTP LOCK request is to be processed. By default, doUnknown
+ * is called.
+ * @param req The HTTP request from the client
+ * @param resf A factory of HTTP responses
+ * @return A HTTP response to be sent to the client
+ * @throws IOException
+ */
+ protected HTTPResponse doLock(HTTPRequest req, HTTPResponse.Factory resf)
+ throws IOException {
+ return doUnknown(req, resf);
+ }
+
+ /** HTTP UNLOCK method handler. This method is called when the
+ * HTTP UNLOCK request is to be processed. By default, doUnknown
+ * is called.
+ * @param req The HTTP request from the client
+ * @param resf A factory of HTTP responses
+ * @return A HTTP response to be sent to the client
+ * @throws IOException
+ */
+ protected HTTPResponse doUnlock(HTTPRequest req, HTTPResponse.Factory
resf)
+ throws IOException {
+ return doUnknown(req, resf);
+ }
+
/** Unknown method handler. This method is called when the
* an unknown HTTP request is to be processed. By default, it is
* responded with a 501.
@@ -243,6 +336,7 @@
protected HTTPResponse dispatch(HTTPRequest req, HTTPResponse.Factory
resf)
throws IOException {
String method = req.getMethod();
+ /* HTTP proper methods */
if (method.equals("HEAD")) return doHead(req, resf);
if (method.equals("GET")) return doGet(req, resf);
if (method.equals("POST")) return doPost(req, resf);
@@ -251,7 +345,17 @@
if (method.equals("OPTIONS")) return doOptions(req, resf);
if (method.equals("TRACE")) return doTrace(req, resf);
if (method.equals("CONNECT")) return doConnect(req, resf);
- /* */ return doUnknown(req, resf);
+
+ /* WebDAV methods */
+ if (method.equals("PROPFIND")) return doPropfind(req, resf);
+ if (method.equals("PROPPATCH")) return doProppatch(req, resf);
+ if (method.equals("MKCOL")) return doMkcol(req, resf);
+ if (method.equals("COPY")) return doCopy(req, resf);
+ if (method.equals("MOVE")) return doMove(req, resf);
+ if (method.equals("LOCK")) return doLock(req, resf);
+ if (method.equals("UNLOCK")) return doUnlock(req, resf);
+
+ /* else: unknown method */ return doUnknown(req, resf);
}
Index: storm/org/nongnu/storm/util/HTTPProxy.java
diff -u storm/org/nongnu/storm/util/HTTPProxy.java:1.44
storm/org/nongnu/storm/util/HTTPProxy.java:1.45
--- storm/org/nongnu/storm/util/HTTPProxy.java:1.44 Mon May 26 14:54:17 2003
+++ storm/org/nongnu/storm/util/HTTPProxy.java Mon May 26 22:22:50 2003
@@ -302,16 +302,35 @@
}
protected String rewriteURIs(String s, String prefix) {
- String l = s.toLowerCase(); // XXX Why this?
+ // Block urns can be in upper or lower or mixed case;
+ // matching on the lower-case version makes
+ // our life much easier.
+ String l = s.toLowerCase();
int i = -1;
- while((i=l.indexOf("urn:x-storm:1.0:", i)) >= 0) {
+ while((i=l.indexOf("urn:x-storm:", i)) >= 0) {
s = s.substring(0, i) + prefix + s.substring(i);
- l = s.toLowerCase(); // XXX and this?
+ l = s.toLowerCase();
i += prefix.length() + 1;
}
return s;
}
+ /** The reverse of rewriteURIs(s, prefix).
+ */
+ protected String unrewriteURIs(String s, String prefix) {
+ // Block urns can be in upper or lower or mixed case;
+ // matching on the lower-case version makes
+ // our life much easier.
+ String l = s.toLowerCase();
+ int i = -1;
+ while((i=l.indexOf(prefix+"urn:x-storm:", i)) >= 0) {
+ s = s.substring(0, i) + s.substring(i+prefix.length());
+ l = s.toLowerCase();
+ i++;
+ }
+ return s;
+ }
+
protected String insertBacklinks(String s, String prefix, BlockId id)
throws IOException {
if(HTTPProxy.dbg) p("Getting HtmlLinkIndex.");
@@ -425,6 +444,12 @@
if(uri.startsWith("/"))
uri = uri.substring(1);
+ boolean rewrite = false;
+ if(uri.startsWith(REWRITE+"/")) {
+ uri = uri.substring(REWRITE.length()+1);
+ rewrite = true;
+ }
+
if(dbg) p("PUT accepted");
PointerId id = new PointerId(uri);
PointerIndex idx =
@@ -445,7 +470,14 @@
BlockOutputStream bos =
pool.getBlockOutputStream(current.getContentType());
- CopyUtil.copy(req.getInputStream(), bos);
+ if(!rewrite || !current.getContentType().equals("text/html")) {
+ CopyUtil.copy(req.getInputStream(), bos);
+ } else {
+ String s = CopyUtil.readString(req.getInputStream());
+ String prefix = ROOTURL+REWRITE+"/";
+ s = unrewriteURIs(s, prefix);
+ bos.write(s.getBytes("US-ASCII"));
+ }
if(dbg) p("Created new block: "+bos.getBlockId());
@@ -536,6 +568,11 @@
if(dbg) p("Return response");
return resp;
}
+
+ protected HTTPResponse doPropfind(HTTPRequest req, HTTPResponse.Factory
resf)
+ throws IOException {
+ // XXX absolutely dummy implementation
+ }
}
protected BlockId getBlockId(String uri) {
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gzz-commits] storm/org/nongnu/storm http/server/HTTPConnecti...,
Benja Fallenstein <=