|
@@ -70,7 +70,7 @@ public class CHttpHandler extends CHandler {
|
|
|
Set<URIFlags> re = URIFlags.collect(URIFlags.FILE);
|
|
Set<URIFlags> re = URIFlags.collect(URIFlags.FILE);
|
|
|
try {
|
|
try {
|
|
|
HttpURLConnection c = connect(ustream, "HEAD");
|
|
HttpURLConnection c = connect(ustream, "HEAD");
|
|
|
- if(2 == (c.getResponseCode() / 100)) {
|
|
|
|
|
|
|
+ if(isSuccess(c)) {
|
|
|
re.add(URIFlags.EXISTS);
|
|
re.add(URIFlags.EXISTS);
|
|
|
re.add(URIFlags.READABLE);
|
|
re.add(URIFlags.READABLE);
|
|
|
}
|
|
}
|
|
@@ -131,7 +131,7 @@ public class CHttpHandler extends CHandler {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public OutputStream ostream(URIHandle ustream) throws IOException {
|
|
public OutputStream ostream(URIHandle ustream) throws IOException {
|
|
|
- HttpURLConnection c = connect(ustream, "PUT");
|
|
|
|
|
|
|
+ HttpURLConnection c = connect(ustream, "POST");
|
|
|
c.connect();
|
|
c.connect();
|
|
|
return c.getOutputStream();
|
|
return c.getOutputStream();
|
|
|
}
|
|
}
|
|
@@ -152,24 +152,44 @@ public class CHttpHandler extends CHandler {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public Writer writer(URIHandle ustream, Charset cs) throws IOException {
|
|
public Writer writer(URIHandle ustream, Charset cs) throws IOException {
|
|
|
- HttpURLConnection c = connect(ustream, "PUT");
|
|
|
|
|
|
|
+ HttpURLConnection c = connect(ustream, "POST");
|
|
|
c.connect();
|
|
c.connect();
|
|
|
return new OutputStreamWriter(c.getOutputStream(), cs);
|
|
return new OutputStreamWriter(c.getOutputStream(), cs);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public Writer writer(URIHandle ustream) throws IOException {
|
|
public Writer writer(URIHandle ustream) throws IOException {
|
|
|
- HttpURLConnection c = connect(ustream, "PUT");
|
|
|
|
|
|
|
+ HttpURLConnection c = connect(ustream, "POST");
|
|
|
c.connect();
|
|
c.connect();
|
|
|
return new OutputStreamWriter(c.getOutputStream(), getContentCharset(c.getContentType()));
|
|
return new OutputStreamWriter(c.getOutputStream(), getContentCharset(c.getContentType()));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void create(URIHandle ustream) throws IOException {
|
|
|
|
|
+ HttpURLConnection c = connect(ustream, "PUT");
|
|
|
|
|
+ if(!isSuccess(c)) {
|
|
|
|
|
+ throw new IOException(c.getResponseCode() + ": " + c.getResponseMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void delete(URIHandle ustream) throws IOException {
|
|
|
|
|
+ HttpURLConnection c = connect(ustream, "DELETE");
|
|
|
|
|
+ if(!isSuccess(c)) {
|
|
|
|
|
+ throw new IOException(c.getResponseCode() + ": " + c.getResponseMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private HttpURLConnection connect(URIHandle ustream, String method) throws IOException {
|
|
private HttpURLConnection connect(URIHandle ustream, String method) throws IOException {
|
|
|
HttpURLConnection c = (HttpURLConnection)((CHttpHandle)ustream).uri.toURL().openConnection();
|
|
HttpURLConnection c = (HttpURLConnection)((CHttpHandle)ustream).uri.toURL().openConnection();
|
|
|
c.setRequestMethod(method);
|
|
c.setRequestMethod(method);
|
|
|
return c;
|
|
return c;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private static boolean isSuccess(HttpURLConnection c) throws IOException {
|
|
|
|
|
+ return 2 == (c.getResponseCode() / 100);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private static Charset getContentCharset(String type) throws IOException {
|
|
private static Charset getContentCharset(String type) throws IOException {
|
|
|
if(null == type) {
|
|
if(null == type) {
|
|
|
throw new IOException("Unknown MIME type");
|
|
throw new IOException("Unknown MIME type");
|